Note that there are some explanatory texts on larger screens.

plurals
  1. PO$_POST variable
    primarykey
    data
    text
    <p>I'm encountering a problem. I'm using Wordpress, but this ain't a Wordpress question.</p> <p>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.</p> <p>Here is my HTML for the forms:</p> <pre><code>&lt;fieldset&gt; &lt;form method="post"&gt; &lt;!-- Some input fields here--&gt; &lt;p class="submit"&gt; &lt;input name="save" type="submit" value="Save changes" /&gt; &lt;input type="hidden" name="action" value="save" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/fieldset&gt; &lt;fieldset&gt; &lt;form method="post"&gt; &lt;p class="submit"&gt; &lt;input name="reset" type="submit" value="Reset" /&gt; &lt;input type="hidden" name="action" value="reset" /&gt; &lt;/p&gt; &lt;/form&gt; &lt;/fieldset&gt; </code></pre> <p>In PHP, I verify them like this:</p> <pre><code>// 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-&gt;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&amp;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-&gt;cp_options as $option) { delete_option($option); } header("Location: themes.php?page=functions.php&amp;reset=true"); die; } </code></pre> <p>The problem is if I change the <code>'reset'</code> or <code>'save'</code> literal to anything else like <code>'reseta'</code> or <code>'saveasdfasd'</code>, <code>$_POST</code> variable won't be empty, but if I dont, then <code>$_POST</code> variable is <code>NULL</code>.</p> <p>Any ideas on why this is happening?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload