Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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