Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there something wrong with my form?
    primarykey
    data
    text
    <p>I have my form working and all of the errors and everything works. But if you have an error, it refreshes the page and removes any text that was inserted before the submit button was clicked and you have to re-enter all of the information. Anyway to fix this?</p> <p>I think it has something to do with not using $_SERVER["PHP_SELF"] in the action of the form. Instead I have action=""</p> <p>I am doing this because the page that needs to be refreshed with the same info has a variable in its url (monthly_specials_info.php?date=Dec10) that was put there from the last page. </p> <p>I tried using</p> <pre><code>&lt;form method="post" action="'.$_SERVER["PHP_SELF"].'?date='.$date.'"&gt; </code></pre> <p>and it produced the right url. but the text was all removed anyway when form was submitted (with errors).. any ideas?</p> <p>Form code:</p> <pre><code>echo ' &lt;div id="specialsForm"&gt;&lt;h3&gt;Interested in this coupon? Email us! &lt;/h3&gt; &lt;form method="post" action="'.$_SERVER["PHP_SELF"].'?date='.$date.'"&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" name="submit" value="Submit Email"/&gt; &lt;/form&gt;&lt;/div&gt; &lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;br /&gt;&lt;br /&gt;'; </code></pre> <p>and the vaildator: </p> <pre><code>if(isset($_POST['submit'])) { $errors = array(); if (empty($name)) { $errors[] = '&lt;span class="error"&gt;ERROR: Missing Name &lt;/span&gt;&lt;br/&gt;'; } if (empty($phone) || empty($email)) { $errors[] = '&lt;span class="error"&gt;ERROR: You must insert a phone number or email&lt;/span&gt;&lt;br/&gt;'; } if (!is_numeric($phone)) { $errors[] = '&lt;span class="error"&gt;ERROR: You must insert a phone number or email&lt;/span&gt;&lt;br/&gt;'; } if (!preg_match('/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}/', strtoupper($email))) { $errors[] = '&lt;span class="error"&gt;ERROR: Please Insert a valid Email&lt;/span&gt;&lt;br/&gt;'; } if ($errors) { echo '&lt;p style="font-weight:bold;text-align:center;"&gt;There were some errors:&lt;/p&gt; '; echo '&lt;ul&gt;&lt;li&gt;', implode('&lt;/li&gt;&lt;li&gt;', $errors), '&lt;/li&gt;&lt;/ul&gt;&lt;br/&gt;'; } else { mail( "email@hotmail.com", "Monthly Specials Email", "Name: $name\n". "Email: $email\n". "Phone Number: $phone\n". "Comment: $comment", "From: $email"); echo'&lt;span id="valid"&gt;Message has been sent&lt;/span&gt;&lt;br/&gt;'; } } </code></pre>
    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.
 

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