• Hallo,
    ik heb contact form die werkt heel goed.
    maar er is 1 kleine probleem de velden worden niet leeg nadat submit button is geklikt.
    plus alle ingevulde namen ,emails,etc blijfen voor auto invulling in de velden staan.
    ik zie dat met JS event listener of met bepaalde JS code wordt deze probleem opgelost .
    maar ik wil weten of er is ook oplossing met simpele php syntax?
    bijvoorbeeld : POST request etc.
    de code is :

    <?php
    
    /*
    * Template Name: Contact
    * Description: Template voor contactpagina
    * Template Post Type: page
    */
    get_header();
    the_content();
    // define variables and set to empty values
    $nameErr = $emailErr = $phoneErr = $contentErr = "";
    $name_sender = $email_sender= $phone = $content =$succes= "";
    
    if ($_SERVER["REQUEST_METHOD"] == "POST") {
    	// post
    	$name_sender = strip_tags($_POST['name_sender']);
    	$email_sender = strip_tags($_POST['email_sender']);
    	$phone = strip_tags($_POST['phone']);
    	$content = strip_tags($_POST['content']);
    	
    	// validate name
    	if (empty($name_sender)) {
    		$nameErr = "Name is required";
    	} else {
    		// check if name only contains letters and whitespace
    		if (!preg_match("/^[a-zA-Z-' ]*$/", $name_sender)) {
    			$nameErr = "Only letters and white space allowed";
    		}
    	}
    
    	// validate email
    	if (empty($email_sender)) {
    		$emailErr = "Email is required";
    	} else {
    		// check if email address is well-formed
    		if (!filter_var($email_sender, FILTER_VALIDATE_EMAIL)) {
    			$emailErr = "Invalid email format";
    		}
    	}
    
    	// validate phone
    	if (empty($phone)) {
    		$phoneErr = "Phone is required";
    	} else {
    		// check if phone is well-formed
    		if(!preg_match("/^[0-9\s\-]+$/", $phone)) {
    			$phoneErr = "Invalid phone number";
    		}
    	}
    
    	// validate content
    	if (empty($content)) {
    		$contentErr = "Content is required";
    	} 
    
    	// send
    	if ( empty($nameErr) && empty($emailErr) && empty($phoneErr) && empty($contentErr) ) {
    		// Variables
    		$to = 'johannes@webdesignleren.com';
    		$subject = 'Contact form';
    		$success = 'Thank you! You will receive a response as soon as possible.';
               
    		
    		// Message content
    	
    
    		// Message content
    	  
    		$content .= "". "\n\n"; 	
    
    		// Headers
    		$headers	 = 'From: ' .$name_sender. ' <' .$email_sender. '>' . PHP_EOL;
    		$headers	.= 'Reply-To: <' .$email_sender. '>' . PHP_EOL;
    		$headers	.= 'Content-Transfer-Encoding: 8bit' . PHP_EOL;
    		$headers	.= 'Content-Type: text/plain; charset=UTF-8' . PHP_EOL;
    
    		// Send email
    		mail($to, $subject,$content, $headers); 
    		echo $success;
    	}
    	
    
    	
    }
    
    // form
    
    ?>
    <div class="container">
    <form id="contact" method="post">
    <h3>Quick Contact</h3>
    <h4>Contact us today, and get reply with in 24 hours!</h4>
    <fieldset>
    <input placeholder="Your name" type="text" name="name_sender" value="<?php echo $name_sender;?>">
    
    <span class="error">* <?php echo $nameErr; ?></span>
    </fieldset>
    <fieldset>
    <input placeholder="Your Email Address" type="text" name="email_sender" value="<?php echo $email_sender;?>">
     
    <span class="error">* <?php echo $emailErr; ?></span>
    </fieldset>
    <fieldset>
    <input placeholder="Your phone number" type="text" name="phone" value="<?php echo $phone;?>">
    
    <span class="error">* <?php echo $phoneErr; ?></span>
    </fieldset>
    <fieldset>
    <textarea placeholder="Type your message here.." type="text" name="content"><?php echo $content;?></textarea>
    <span class="error">* <?php echo $contentErr; ?></span>
    </fieldset>
    <fieldset>
    <button name="submit" type="submit" id="contact-submit">Submit</button></fieldset>
    </form></div>
    <?php
    
    get_footer();

    ik zou waarderen als iemand heeft een idea welke php syntax code ik moet gebruiken om deze probleem op te lossen.
    dank u wel
    johannes

    De pagina waar ik hulp bij nodig heb: [log in om de link te zien]

  • Het onderwerp ‘na submit wordt geklikt de velden van contact-form worden niet leeg?’ is gesloten voor nieuwe reacties.