Jump to content

Best Way to Reset Form


HenryCan

Recommended Posts

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....

Link to comment
https://forums.phpfreaks.com/topic/273332-best-way-to-reset-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.