Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'd use an empty <code>action</code> and post the form to itself. That way, you'll be able to display the errors in the same page:</p> <p><strong>The structure:</strong></p> <pre><code>&lt;?php if(isset($_POST['submit'])){ //validation } &lt;form action="" method="post"&gt; &lt;!-- input fields here --&gt; &lt;/form </code></pre> <p><strong>Full code:</strong></p> <pre><code>&lt;?php if(isset( $_POST['submitbutton']) ){ $email_to = "foo@bar.com"; //my email $email_subject = "form submission"; $email_from ="form test"; $biz_email = $_POST['biz_email']; $error_message = ""; function died($error) { echo "There are errors in your submission:&lt;br /&gt;&lt;br /&gt;"; echo $error."&lt;br /&gt;&lt;br /&gt;"; echo "Please go back and fix these errors.&lt;br /&gt;&lt;br /&gt;"; die(); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Email: ".clean_string($biz_email)."\n"; $headers = 'From: '.$biz_email."\r\n". 'Reply-To: '.$biz_email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } ?&gt; &lt;!-- form start --&gt; &lt;div id="notification"&gt;&lt;/div&gt; &lt;form id="downloadForm" method="post" action=""&gt; &lt;label for="biz_email"&gt;Business Email:&lt;/label&gt;&lt;input type="text" name="biz_email"&gt; &lt;input type="submit" id="submit" name="submitbutton" class="submit_button"&gt;&lt;/div&gt; &lt;/form&gt; &lt;!-- form end --&gt; </code></pre> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload