I do have a problem regarding the plug-in settings that I've made.

I've created a simple textbox and a submit button and run it on the admin page setting. The name of the textbox and submit button is myfirst_plugin.php. Now all I just want is to fill the field and when you refresh it, it'll show the last attributes that you entered on the name, email, comments etc. Would that be possible? How can I use the get_option and update_option?

For example, on the name field I type the name “Jayson Parker”, if I am going to refresh it again, Jayson Parker would be on the name field even if I refresh it.

Hope someone can

Plugin Name: Wordpress Event Plugin
Plugin URI:
Description: plugin for wordpress
Version: 1.0
Author URI:[email protected]
License: GPLv2

// Admin Page

    add_action('admin_menu', 'myfirstplugin_admin_actions');

    function myfirstplugin_admin_actions() {
            "Event Settings",
            "Event Settings",


     function myfirstplugin_admin_page() {


1 Answer 1


Handling form fields is not related to WordPress and is off-topic here, BTW I'm answering this on how to use the options table. And your code you presented here is not relevant to your question.

Ok, first of all having form data into a field after submission could put you in risk of entering duplicate entries. BTW here's how you can do that (follow the inline comments):

if( isset($_POST['x_submit']) ) {
    $data = array(
            'name'  => sanitize_text_field( $_POST['name'] ),
            'email' => sanitize_email( $_POST['email'] ),
            'comment'   => esc_textarea( $_POST['comment'] )
    //entering data into options table
    update_option( 'my_option_key', $data );

//having data from options table
$db_values = get_option( 'my_option_key' );

//setting empty values to avoid 'undefined index' warning
$name = '';
$email = '';
$comment = '';

//if there's any data in options table, updating our variables with relevant data
if( $db_values ) {
    $name = $db_values['name'] ? $db_values['name'] : '';
    $email = $db_values['email'] ? $db_values['email'] : '';
    $comment = $db_values['comment'] ? $db_values['comment'] : '';
<form method="post">
    <label>Name <input type="text" name="name" value="<?php echo isset($_POST['name']) ? $_POST['name'] : $name; ?>"></label><br>
    <label>Email <input type="email" name="email" value="<?php echo isset($_POST['email']) ? $_POST['email'] : $email; ?>"></label><br>
    <label>Comment <textarea name="comment" cols="30" rows="10"><?php echo isset($_POST['comment']) ? $_POST['comment'] : $comment; ?></textarea></label>
    <input type="submit" name="x_submit" value="Submit">

P.S.: NOTHING IS TESTED here, just follow the procedures and change it as it suits you. And important, do the necessary escaping and sanitizing.

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.