Reputation: 63
I am trying to create an option panel WordPress theme. The option page displays fine but on submit of form I get:
ERROR: options page not found.
This is my code.
<?php
/*
Plugin Name: Option Man
Description: A test plugin to manage site
Author: Pravin Mishra
Version: 0.1
*/
add_action('admin_menu', 'test_plugin_setup_menu');
function test_plugin_setup_menu(){
add_menu_page( 'Option-Man-Plugin', 'Option Man', 'manage_options', 'test-plugin', 'test_init' );
}
function test_init(){
add_action( 'admin_init', 'register_my_setting' );
function register_my_setting() {
//register_setting( 'myoptions-group', 'my_option_name', 'intval' );
register_setting(‘myoptions-group’, ‘testplugin_option1′);
register_setting(‘myoptions-group’, ‘testplugin_option2′);
}
echo "Hello world!";
?>
<div class="wrap">
<u><h2>BS3 Custom Options</h2></u>
<form method="post" action="http://192.168.2.139/web/wp-admin/options.php">
<?php //settings_fields( 'myoptions-group' );
//do_settings_sections( 'myoption-group' );
settings_fields( 'myoptions-group' );
?>
<input type="text" name="testplugin-option1" value="<?php echo get_option('testplugin_option1'); ?>"/>
<input type="text" name="testplugin-option2" value="<?php echo get_option('testplugin_option2'); ?>"/>
<?php
submit_button();
?>
</form>
</div>
<?php
}
?>
Upvotes: 0
Views: 146
Reputation: 903
I have correct the code now it's working fine.
add_action('admin_menu', 'test_plugin_setup_menu');
function test_plugin_setup_menu(){
add_menu_page( 'Option-Man-Plugin', 'Option Man', 'manage_options', __FILE__, 'test_init' );
add_action( 'admin_init', 'register_my_setting' );
}
function register_my_setting() {
//register_setting( 'myoptions-group', 'my_option_name', 'intval' );
register_setting('myoptions-group', 'testplugin_option1');
register_setting('myoptions-group', 'testplugin_option2');
}
function test_init(){
?>
<div class="wrap">
<u><h2>BS3 Custom Options</h2></u>
<form method="post" action="options.php" enctype="multipart/form-data">
<?php
settings_fields('myoptions-group');
do_settings_sections('myoptions-group');
?>
<input type="text" name="testplugin_option1" value="<?php echo get_option('testplugin_option1'); ?>"/>
<input type="text" name="testplugin_option2" value="<?php echo get_option('testplugin_option2'); ?>"/>
<?php
submit_button();
?>
</form>
</div>
<?php
}
Your field name and option name is not same and also the options page path is wrong.
Upvotes: 1
Reputation: 6080
Change <form method="post" action="http://192.168.2.139/web/wp-admin/options.php">
to <form method="post" action="">
Upvotes: 1