I'm encountering a problem. I'm using Wordpress, but this ain't a Wordpress question.
I'm using two forms, on one form I have all the input fields and one hidden input field which I use for checking which form the user has submitted. I have saved its value as 'save'. There is another form which is just for resetting all the options and its value is 'reset'. In PHP, I check the value of the hidden field and take respective actions. But the problem is that the reset thingy isn't working.
Here is my HTML for the forms:
<fieldset>
<form method="post">
<!-- Some input fields here-->
<p class="submit">
<input name="save" type="submit" value="Save changes" />
<input type="hidden" name="action" value="save" />
</p>
</form>
</fieldset>
<fieldset>
<form method="post">
<p class="submit">
<input name="reset" type="submit" value="Reset" />
<input type="hidden" name="action" value="reset" />
</p>
</form>
</fieldset>
In PHP, I verify them like this:
// if I change the 'save' literal to something else like 'savea', $_POST variable will not be empty
// but if I dont, then $_POST variable is NULL
if ('save' == $_POST['action']) {
foreach ($this->cp_options as $option) {
if (isset($_POST[$option['id']])) {
update_option($option['id'], $_POST[$option['id']]);
}
else {
delete_option($option['id']);
}
}
header("Location: themes.php?page=functions.php&saved=true");
die;
}
// if I change the 'reset' literal to something else like 'reseta', $_POST variable will not be empty
// but if I dont, then $_POST variable is NULL
elseif ('reset' == $_POST['action']) {
foreach($this->cp_options as $option) {
delete_option($option);
}
header("Location: themes.php?page=functions.php&reset=true");
die;
}
The problem is if I change the 'reset'
or 'save'
literal to anything else like 'reseta'
or 'saveasdfasd'
, $_POST
variable won't be empty, but if I dont, then $_POST
variable is NULL
.
Any ideas on why this is happening?