4

I'm not sure what's happening here, since this has worked in another plugin I've created. I'm simply trying to store data in the options table. Here is the code I'm using:

function on_myplugin_start () {         
register_setting('first_tab_options', 'first_tab_items');
}

add_action('admin_init','on_myplugin_start');

Here is the form that gets submitted:

<form action="options.php" method="post" >
<?php
 settings_fields( 'first_tab_options' );
 ?>
<input type="text" name="some_name" value="">
<input type="submit" value="Save Settings" name="submit" class="button-primary">
</form>

That's it..when I look at the source code, everything looks fine...there is all the hidden fields put in by the settings API..but when I put in a value and hit submit (and it says successfully saved, nothing is in the database field that was successfully created (first_tab_items).

I would appreciate any help on this....thanks

9

...because your input (POST) name needs to match the one in your register_setting call:

register_setting( 'first_tab_options', 'first_tab_items' );
....
<input type="text" name="first_tab_items"...

Otherwise how the hell does WP know that some_name in POST holds your option data? ;)

0

Adding to TheDeadMedic's answer: if you want to register just one setting for an entire form like you implied, you can use an array:

<form action="options.php" method="post" >
<?php
    settings_fields( 'first_tab_options' );
?>
<input type="text" name="first_tab_items[some_name]" value="">
<input type="text" name="first_tab_items[some_name2]" value="">
<input type="submit" value="Save Settings" name="submit" class="button-primary">
</form>

And register:

register_setting('first_tab_options', 'first_tab_items');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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