Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I refresh the page when a form is submitted & give an error message?
    primarykey
    data
    text
    <p>What I have right now is a form with simple input fields such as name, phone number, email, and comment.</p> <pre><code>&lt;div id="specialsForm"&gt;&lt;h3&gt;Interested in this coupon? Email us! &lt;/h3&gt; &lt;form method="post" action="emailMonthlySpecials.php"&gt; Name: &lt;input name="name" type="text" /&gt;&lt;br /&gt; Email: &lt;input name="email" type="text" /&gt;&lt;br /&gt; Phone Number: &lt;input name="phone" type="text" /&gt;&lt;br /&gt;&lt;br /&gt; Comment: &lt;br/&gt; &lt;textarea name="comment" rows="5" cols="30"&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;br /&gt; &lt;input type="submit" value="Submit Email"/&gt; &lt;/form&gt;&lt;/div&gt; </code></pre> <p>In my emailMonthlySpecials.php I have the following code:</p> <pre><code> $name = $_REQUEST['name'] ; $email = $_REQUEST['email'] ; $phone = $_REQUEST['phone'] ; $comment = $_REQUEST['comment'] ; if(!empty($name) &amp;&amp; (!empty($email) || !empty($phone))) { mail("my.email@hotmail.com", "Monthly Specials Email", "Name: $name Email: $email Phone Number: $phone Comment: $comment", "From: $email" ); } else { echo '&lt;span class="error"&gt;A name, comment, phone number/email is required&lt;/span&gt;&lt;br /&gt;'; }; </code></pre> <p>It goes to a new page and shows the error (if there is one) and if not it goes to a blank page (I know how to make it go to a thank you page but it needs to be kept on its current page) It does work with sending the info to the email.</p> <p>I have tried</p> <pre><code> header("Location: ".$_SERVER["PHP_SELF"]); </code></pre> <p>And it didnt work.. Any ideas?</p>
    singulars
    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.
 

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