options.php does not save option value to database

Question

seems it is duplicate question but i tried the existing solution and still not solved my problem.
i creating the test plugin and i have problem in submitting value to options.php which is not store the value to corresponding option and still is null.

this is how i registered my option settings.

public function registerCustomFields(){

        register_setting( 'opt_grp', 'last_name',array($this->callBacks,'pluginOptionsGroup'));
        add_settings_section( 'section_index', 'section title', array($this->callBacks,'pluginSectionCB'), 'adm_menu' );
        add_settings_field( 'last_name', 'test text', array( $this->callBacks, 'pluginTextExample' ), 'adm_menu', 'section_index');
    }
add_action('admin_init',array($this,'registerCustomFields'));

and here is above callbacks

public function pluginOptionsGroup($input){
        return $input;
    }

    public function pluginSectionCB(){
        echo "Feachures Management";
    }

    public function pluginTextExample(){
        $value = get_option('last_name');
        
        echo '<input type="text" class="ui-toggle" id="last_name" name="last_name" value="'.$value.'" >';
    }

and this is the form in myadmin.php page

<div>
   
    <?php settings_errors(); ?>

    <form type="POST" action="options.php">
        <?php 
            settings_fields( 'opt_grp' );
            
            do_settings_sections( 'adm_menu' );
            
            submit_button();
            
            ?>

        
    </form>

</div>

i can find the option in option table but its always null,and when i change value in database itself its ok and by refreshing page it comes to textbox

0
Rouzbeh Zarandi 4 months 0 Answers 9 views 0

Leave an answer