• I have created a menu on admin and created a form with only two fields. Now the problem is that i dont know how can i know when when the form whether the form is submitted or not. Also nothing is displayed that shows that settings are saved or like wise…. My plugin code is that:-

    <?php
    /*
    plugin name: my plugin
    plugin uri: https://www.example.com
    description: This is just testing plugin
    version: 1.0
    author: junaid rehman
    author uri: https://www.example.com
    */
    add_action('admin_menu', 'jun_create_text');
    
    if ( 'save' == $_REQUEST['action'] ) {
    	add_option("yourname", esc_attr($_REQUEST["yourname"]));
    	add_option("fname", esc_attr($_REQUEST["fname"]));
    	add_filter('wp_footer', 'jun_footer');
    }
    function jun_footer($content){
    	echo "Your Name is ".get_option("yourname")."<br>";
    	echo "Your Father Name is ".get_option("fname")."<br>";
    	}
    function jun_create_text(){
    		add_menu_page( 'My Plugin Settings', 'Plugin Styling',
    'manage_options', __FILE__, 'jun_styling_settings' );
    }
    
    function jun_styling_settings(){
    	?>
       <div class="wrap">
    	<?php screen_icon( 'plugins' ); ?>
    	<h2>My Plugin</h2>
        <form method="POST" action="">
        <table class="form-table">
        <tr valign="top">
        <th scope="row"><label for="yourname">Your Name</label> </th>
        <td ><input maxlength="45" size="25" name="yourname" value=""/> </td>
        </tr >
        <tr valign="top">
        <th scope="row"><label for="fname">Father Name</label> </th>
        <td ><input maxlength="45" size="25" name="fname" value=""/> </td>
        </tr >
        <tr valign="top">
        <td>
        <input type="submit" name="save" value="Save Options"
        class="button-primary" />
        <input type="submit" name="reset" value="Reset"
        class="button-secondary" />
        </td>
        </tr>
        </table>
        </form>
        </div>
    
    <?php
    }

Viewing 1 replies (of 1 total)
  • Thread Starter junaidrehman

    (@junaidrehman)

    I want to say that following code is not working:-

    if ( 'save' == $_REQUEST['action'] ) {
    	add_option("yourname", esc_attr($_REQUEST["yourname"]));
    	add_option("fname", esc_attr($_REQUEST["fname"]));
    	add_filter('wp_footer', 'jun_footer');
    }

Viewing 1 replies (of 1 total)
  • The topic ‘Problem while creating simple plugin’ is closed to new replies.