HenryCan Posted January 18, 2013 Share Posted January 18, 2013 I'm a PHP newbie (but experienced in several other languages) and I'm looking for the best way to reset a form, i.e. restore it to its initial values. I have a Reset button on the form and I know I can detect that it was pressed with if (isset($_POST['resetButton'])) { } where resetButton is the value I gave to the name attribute of the button. I just need to know how to get the various values on the form back to their original state. Typically, that would be blank for text fields and default values for radio buttons, etc. I don't know if there is a single all-purpose function that will reset everything in one go or if I have to set each field to its original value with individual statements. Either approach is fine by me. Frankly, at this stage of the game, I'd be happy to get even a not-so-good method of doing this! I have spent close to two hours googling and searching on every phrase I could think of but all I get is items about how to prevent blanks in forms; not a word on how to blank out a form field. Maybe I'm just having a Stupid Day but it shouldn't be this hard to find out how to set a field to blank! For what it's worth, I tried setting a text field to blank with this: $_POST['name'] = ''; //blank out name but nothing happened. There was no error message and the field was unchanged but I know the statement executed. I'd prefer to stay away from the klugey mess called Javascript if I can.... Quote Link to comment Share on other sites More sharing options...
cpd Posted January 18, 2013 Share Posted January 18, 2013 <input type="reset" name="reset" value="Reset" /> Quote Link to comment Share on other sites More sharing options...
HenryCan Posted January 18, 2013 Author Share Posted January 18, 2013 I was sure I tried that FIRST but it never did anything. But it works perfectly now. Obviously, I miscoded it in some way.... Thank you, that was very helpful, cpd! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.