Forums

Custom page templates with forms in (2 posts)

  1. thelastknight
    Member
    Posted 3 years ago #

    Hi,

    I've tried creating a form using a template page, then submitting the form to another template page which gets the variables and passes them through mail() as per most contact forms.

    This always gave me a 404 error when passing the information onto the page with mail() in, but if no data in the form was passed it would find the page?

    I read that WordPress can't handle this form some reason or another, so I'm passing the data to the form data to the same page using <form action"" method="post" > but still get the 404 error. My code works outside of WordPress.

    Any ideas people?

    Here's my code for my contact template (A shortened version)

    <?php 
    
    		if (array_key_exists('form', $_POST)) {
    
    			$name = $_POST['name'];
    
    			if (empty($name)) {
    
    				echo "You forgot to enter your name";
    				$process = false;
    
    			} else {
    
    				$process = true;
    
    			}
    
    			if ($process == true) {
    
    				echo "Your form has been submitted successfully";
    
    				$to = "email@email.co.uk";
    
    				$subject = "PHP Form";
    
    				$message = "Yep, it seemed to work!";
    
    				$from = "email@email.co.uk";
    
    				$headers = "From: $from\r\n";
    
    				$headers .= "Reply-To: $to\r\n";
    
    				mail($to, $subject, $message, $headers);
    
    			}
    
    		} else { 
    
    	?>
    
         <form action="" method="post">
    
         	<input name="name" type="text" />
    
              <input name="" type="submit" />
    
              <input name="form" type="hidden" />
    
         </form>
    
         <?php } ?>
  2. stvwlf
    Member
    Posted 3 years ago #

    A suggestion - there are a number of WP plugins existing, ranging from very simple to quite involved, that are contact form submitters and emailers. They require you to do next to nothing to get them to work.

    If you want to use your own code, that's fine, and go for it. But if you just want the functionality, its available for free and you can have it installed and working in 15 minutes.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.