Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't clear the form after successful completion
    primarykey
    data
    text
    <p>Hi I have a "Sticky" form that after successful completion I want to clear the fields I tried placing the $_POST = array(); in different sections of the IF statements,</p> <p>This is the entire file, it is a form that get's sent to itself and records what you wrote in a file outside the webroot</p> <p>Thanks for any help</p> <pre><code> &lt;!-- BEGIN CHANGABLE CONTENT --&gt; &lt;?php require('templates/header.html') ?&gt; &lt;div id="main" role="main"&gt; &lt;h1&gt;Welcome to the site&lt;/h1&gt; &lt;h2&gt;Please fill out the form&lt;/h2&gt; &lt;p&gt;Register and become a member!&lt;br /&gt;Members enjoy newsletters and free swag courtesy of Tony Browns Design&lt;/p&gt; &lt;form action="index.php" method='post' id='login_form'&gt; &lt;legend&gt;&lt;h2&gt;Registration Form&lt;/h2&gt;&lt;/legend&gt; &lt;fieldset&gt; &lt;div&gt; &lt;label for="fname"&gt;First Name: &lt;/label&gt; &lt;input type="text" name='fname' id='fname' size='20' value="&lt;?php if (isset($_POST['fname'])){echo htmlspecialchars($_POST['fname']);} ?&gt;" /&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="lname"&gt;Last Name: &lt;/label&gt; &lt;input type="text" name='lname' id='lname' size='20' value="&lt;?php if(isset($_POST['lname'])){echo htmlspecialchars($_POST['lname']);} ?&gt;" /&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="email"&gt;Email: &lt;/label&gt; &lt;input type="text" name='email' id='email' size='20' value="&lt;?php if(isset($_POST['fname'])) {echo htmlspecialchars($_POST['email']);} ?&gt;" /&gt; &lt;/div&gt; &lt;div&gt; &lt;label for="quotes" class='move-top'&gt;Quote: &lt;/label&gt; &lt;textarea name="quotes" id="quote" cols="22" rows="8"&gt;Enter your quotation here.&lt;/textarea&gt;&lt;br /&gt; &lt;/div&gt; &lt;div&gt; &lt;input type="submit" value='submit' /&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;?php $file = '../quotes_from_users.txt'; //Check if form is submitted if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (empty($_POST['fname']) &amp;&amp; (empty($_POST['lname']) &amp;&amp; (empty($_POST['email'])))) { echo '&lt;p style="color: #d00; text-shadow: -1px -1px 0 #200; font-size: 1.4em;"&gt;You need to fill in the all the fields!&lt;/p&gt;'; } if (!empty($_POST['quotes']) &amp;&amp; ($_POST['quotes'] != 'Enter your quotation here.') ) { if (is_writable($file)) { file_put_contents($file, $_POST['quotes'] . PHP_EOL, FILE_APPEND | LOCK_EX); echo '&lt;p style="color= #cf5 font-size: 1.4em;"&gt;Your quote has been stored.&lt;/p&gt;'; $_POST = array(); } else { echo '&lt;p style="color: #d00; text-shadow: -1px -1px 0 #200;"&gt;Your quote could not be stored due to a systems error, sorry about that!&lt;/p&gt;'; } } else { echo '&lt;p style="color: #d00; text-shadow: -1px -1px 0 #200; font-size: 1.4em;"&gt;Please enter a quote!&lt;/p&gt;'; } } ?&gt; &lt;?php require('templates/footer.html'); ?&gt; &lt;/div&gt; &lt;!-- END CHANGABLE CONTENT --&gt; </code></pre>
    singulars
    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