0

I'm generating this form using Settings API:

<form action="options.php" method="post">   
   <?php settings_fields('XX_theme_settings'); do_settings_sections('my_settings'); ?>
   <input type="hidden" name="foo" value="bar" />
   <input name="SubmitButton" type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" />   
</form>

Validation callbacks $input array returns only 'my_settings' input fields.

How do I access foo (bar) input's value and submit button's name SubmitButton?

This doesn't work for the hidden input:

my_validation($input) {
   $foo = $input['foo'];
}

And when it comes to the submit button I don't even know where to start.

2
  • 1
    and $foo = $_POST['foo']? I don't use settings API too often, just a guess. Commented Mar 2, 2012 at 23:18
  • Christ, I was trying to do everything within Settings API and didn't even tried $_POST array. Of course you were right, it works! Please repost your comment as an answer so I will be able to accept it. Thank you! :) Commented Mar 3, 2012 at 0:10

1 Answer 1

4

Using $_POST is too low level. Simply give it the same name as your other options. When you options are displayed they should have the names of the form: my_settings[a_particular_option]. For instance:

<input name="my_settings[some_input_option]"/>

Then for your hidden input and submit button:

<input type="hiddden" name="my_settings[foo]" value="bar"/>
<input name="my_settings[SubmitButton]" type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>"/>

In your validation array

my_validation($input) {
   $foo = $input['foo'];
   $submit = $input['SubmitButton'];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.