admin管理员组文章数量:1122832
I want to save the value of input data and retrieve it. I'm new to creating WordPress plugin and I don't know how to get the value from the form. I have seen some plugin development tutorials but I'm unable to develop it properly. Here is my code:
/*
Plugin Name: My Custorm Form
Plugin URI:
Description: New plugin
Version: 0.1
Author: RB
*/
function my_plugin_settings()
{
add_menu_page( 'My Plugin',
'myCust Form',
'administrator',
'insert-my-plugin_bro',
'my_plugin_settings_page',
'dashicons-translation',
'60'
);
}
add_action('admin_menu', 'my_plugin_settings');
function my_plugin_options()
{
register_setting('my-form-group','user_input_name');
}
add_action('admin_init', 'my_plugin_options');
function my_plugin_settings_page()
{
echo "<h1>My Plugin Settings</h1>";
?>
<div class="wrap">
<form action="options.php" method="post">
<?php settings_fields('my-form-group'); ?>
<b>Enter a name to display:</b><br/>
<input type="text" name="default-image-url" value="" >
<?php submit_button(); ?>
</form>
</div>
<?php
}
?>
I want to save the value of input data and retrieve it. I'm new to creating WordPress plugin and I don't know how to get the value from the form. I have seen some plugin development tutorials but I'm unable to develop it properly. Here is my code:
/*
Plugin Name: My Custorm Form
Plugin URI: https://abcd.com
Description: New plugin
Version: 0.1
Author: RB
*/
function my_plugin_settings()
{
add_menu_page( 'My Plugin',
'myCust Form',
'administrator',
'insert-my-plugin_bro',
'my_plugin_settings_page',
'dashicons-translation',
'60'
);
}
add_action('admin_menu', 'my_plugin_settings');
function my_plugin_options()
{
register_setting('my-form-group','user_input_name');
}
add_action('admin_init', 'my_plugin_options');
function my_plugin_settings_page()
{
echo "<h1>My Plugin Settings</h1>";
?>
<div class="wrap">
<form action="options.php" method="post">
<?php settings_fields('my-form-group'); ?>
<b>Enter a name to display:</b><br/>
<input type="text" name="default-image-url" value="" >
<?php submit_button(); ?>
</form>
</div>
<?php
}
?>
Share
Improve this question
edited Nov 28, 2017 at 18:06
fuxia♦
107k38 gold badges255 silver badges459 bronze badges
asked Nov 28, 2017 at 17:25
RajB009RajB009
1211 silver badge2 bronze badges
1 Answer
Reset to default 0You were almost there. I have modified your code. You could try this:
<?php
add_action('admin_menu', 'my_plugin_create_menu');
function my_plugin_create_menu() {
//create new top-level menu
add_menu_page( 'My Plugin',
'myCust Form',
'administrator',
'insert-my-plugin_bro',
'my_plugin_settings_page',
'dashicons-translation',
'60'
);
//call register settings function
add_action( 'admin_init', 'register_my_plugin_settings' );
}
function register_my_plugin_settings() {
//register our settings
register_setting( 'my-plugin-settings-group', 'display_name' );
}
function my_plugin_settings_page() {
?>
<div class="wrap">
<h1>My Plugin Settings</h1>
<form method="post" action="options.php">
<?php settings_fields( 'my-plugin-settings-group' ); ?>
<?php do_settings_sections( 'my-plugin-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Enter a name to display</th>
<td><input type="text" name="display_name" value="<?php echo esc_attr( get_option('display_name') ); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php } ?>
Wordpress also has a documentation for this . It should help you
本文标签: How to retrieve form data
版权声明:本文标题:How to retrieve form data? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736293148a1929083.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论