Clear the form field after successful submission of php form

后端 未结 12 1723
春和景丽
春和景丽 2020-12-16 06:10

I am making a simple Form the problem i am facing is when i submit the form values still remains in the field. and I want to clear it after SUCCESSFUL submission. Please hel

相关标签:
12条回答
  • 2020-12-16 07:00

    I was facing this similiar problem and did not want to use header() to redirect to another page.

    Solution:

    Use $_POST = array(); to reset the $_POST array at the top of the form, along with the code used to process the form.

    The error or success messages can be conditionally added after the form. Hope this helps :)

    0 讨论(0)
  • 2020-12-16 07:00

    this code will help you

    if($insert){$_POST['name']="";$_POST['content']=""}
    
    0 讨论(0)
  • 2020-12-16 07:02

    Put the onClick function in the button submit:

    <input type="text" id="firstname">
    <input type="text" id="lastname">
    <input type="submit" value="Submit" onClick="clearform();" />
    

    In the <head>, define the function clearform(), and set the textbox value to "":

    function clearform()
    {
        document.getElementById("firstname").value=""; //don't forget to set the textbox id
        document.getElementById("lastname").value="";
    }
    

    This way the textbox will be cleared when you click the submit button.

    0 讨论(0)
  • 2020-12-16 07:07

    I have a simple form to submit testimonials, I also was having trouble clearing the form, what I did was after the query is submitted successfully I and before redirecting to another page I cleared the imputs $name =''; ect. The page submitted and redirected with no errors.

    0 讨论(0)
  • 2020-12-16 07:07

    You can check this also

    <form id="form1" method="post">
    <label class="w">Plan :</label>
    <select autofocus="" name="plan" required="required">
        <option value="">Select One</option>
        <option value="FREE Account">FREE Account</option>
        <option value="Premium Account Monthly">Premium Account Monthly</option>
        <option value="Premium Account Yearly">Premium Account Yearly</option>
    </select>
    <br>
    <label class="w">First Name :</label><input name="firstname" type="text" placeholder="First Name" required="required" ><br>
    <label class="w">Last Name :</label><input name="lastname" type="text" placeholder="Last Name" required="required" ><br>
    <label class="w">E-mail ID :</label><input name="email" type="email" placeholder="Enter Email" required="required" ><br>
    <label class="w">Password :</label><input name="password" type="password" placeholder="********" required="required"><br>
    <label class="w">Re-Enter Password :</label><input name="confirmpassword" type="password" placeholder="********" required="required"><br>
    <label class="w">Street Address 1 :</label><input name="strtadd1" type="text" placeholder="street address first" required="required"><br>
    <label class="w">Street Address 2 :</label><input name="strtadd2" type="text" placeholder="street address second" ><br>
    <label class="w">City :</label>
    <input name="city" type="text" placeholder="City" required="required"><br>
    <label class="w">Country :</label>
    <select autofocus id="a1_txtBox1" name="country" required="required" placeholder="select one">
    <option>Select One</option>
    <option>UK</option>
    <option>US</option>
    </select>
    <br>
    <br>
    <input type="reset" value="Submit" />
    
    </form>

    0 讨论(0)
  • 2020-12-16 07:14

    If you want your form's field clear, you must only add a delay in the onClick event like:

    <input name="submit" id="MyButton" type="submit" class="btn-lg" value="ClickMe" onClick="setTimeout('clearform()', 2000 );"
    
    onClick="setTimeout('clearform()', 1500 );" . in 1,5 seconds its clear
    
    document.getElementById("name").value = "";  <<<<<<just correct this
    document.getElementById("telephone").value = "";    <<<<<correct this
    

    By clearform(), I mean your clearing-fields function.

    0 讨论(0)
提交回复
热议问题