title: Clear forms on successful submission
body: <p>I have a registration form where the form will:</p>
  
  <ol>
  <li>Clear form on a successful submission</li>
  <li>Don't clear form on an error submission (in my case, unmatched passwords)</li>
  </ol>
  
  <p>Here's my code:</p>
  
  <pre><code>&lt;input name="uname" type="text" class="form-control" id="uname" placeholder="Username" value="&lt;?php if (!empty($_POST["uname"])) { echo $_POST["uname"]; } else { echo ''; };  ?&gt;" required&gt;
  </code></pre>
  
  <p>This code works for the <strong>don't clear form on an error submission</strong>. Although the submission is successful, the form still keeps the data after the form submission. Since, i'm using this code, obviously the reset button won't work too. Therefore, how do i clear it after <strong>successful submission</strong>?</p>
  
  <p>Anyway here's the code for form validation:</p>
  
  <pre><code>if (isset($_POST['submit'])) {
  
                try {
  
                  if ($_POST["pwd"] == $_POST["cpwd"]) {//matched passwords
  
                    $stmt = $conn-&gt;prepare("INSERT INTO tbl_customers(fld_customer_fname,
                      fld_customer_lname, fld_customer_gender, fld_customer_phone, fld_customer_email, fld_customer_username, fld_customer_password) VALUES(:fname, :lname,
                      :gender, :phone, :email, :uname, :pwd)");
  
                    $stmt-&gt;bindParam(':fname', $fname, PDO::PARAM_STR);
                    $stmt-&gt;bindParam(':lname', $lname, PDO::PARAM_STR);
                    $stmt-&gt;bindParam(':gender', $gender, PDO::PARAM_STR);
                    $stmt-&gt;bindParam(':phone', $phone, PDO::PARAM_STR);
                    $stmt-&gt;bindParam(':email', $email, PDO::PARAM_STR);
                    $stmt-&gt;bindParam(':uname', $uname, PDO::PARAM_STR);
                    $stmt-&gt;bindParam(':pwd', $pwd, PDO::PARAM_STR);
  
                    $fname = $_POST['fname'];
                    $lname = $_POST['lname'];
                    $gender =  $_POST['gender'];
                    $phone = $_POST['phone'];
                    $email = $_POST['email'];
                    $uname = $_POST['uname'];
                    $pwd = $_POST['pwd'];
  
                    $stmt-&gt;execute();
                    ?&gt;
                    &lt;br&gt;
                    &lt;div class="alert alert-success fade in"&gt;
                      &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;
                        &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                      &lt;strong&gt;Success!&lt;/strong&gt; Account created.
                    &lt;/div&gt;
                    &lt;?php
                  }
                  else{//unmatched passwords
                    ?&gt;
                    &lt;br&gt;
                    &lt;div class="alert alert-danger fade in"&gt;
                      &lt;button type="button" class="close" data-dismiss="alert" aria-label="Close"&gt;
                        &lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;
                      &lt;/button&gt;
                      &lt;strong&gt;Error!&lt;/strong&gt; Passwords do not match.
                    &lt;/div&gt;
                    &lt;?php
                  }
                }
  </code></pre>