• Hi

    I’ve using this tutorial to create a custom admin menu where the administrator can write a message that will display on the frontpage. But if there is no message, the frontpage output should be hidden and the input field should be cleared.

    My question is; how do I create a clear/reset button that hides the css class on the frontpage?

    Thanks for reading this far 😀
    //MadsRH

    This is the plugin:

    /* Runs when plugin is activated */
    register_activation_hook(__FILE__,'hello_world_install'); 
    
    /* Runs on plugin deactivation*/
    register_deactivation_hook( __FILE__, 'hello_world_remove' );
    
    function hello_world_install() {
    /* Creates new database field */
    add_option("vigtigt_data", 'Default', '', 'yes');
    }
    
    function hello_world_remove() {
    /* Deletes the database field */
    delete_option('vigtigt_data');
    }
    
    /*———————————————————————*/
    if ( is_admin() ){
    
    /* Call the html code */
    add_action('admin_menu', 'hello_world_admin_menu');
    
    function hello_world_admin_menu() {
    add_menu_page('Vigtigt', 'Vigtige beskeder!', '1',
    'hello-world', 'hello_world_html_page');
    }
    }
    /*———————————————————————*/
    /*———————————————————————*/
    function hello_world_html_page() {
    ?>
    <div>
    <h2>Vigtige beskeder!</h2>
    
    <form method="post" action="options.php">
    <?php wp_nonce_field('update-options'); ?>
    
    <table width="900">
    <tr valign="top">
    <th width="140" scope="row">Skriv din tekst her:</th>
    <td width="700">
    <input size="76" name="vigtigt_data" type="text" id="vigtigt_data"
    value="<?php echo get_option('vigtigt_data'); ?>" />
    (f.eks. Undervisning er aflyst pga. sne!)</td>
    </tr>
    <tr><td>
    
    </td></tr>
    </table>
    
    <input type="hidden" name="action" value="update" />
    <input type="hidden" name="page_options" value="vigtigt_data" />
    
    <p>
    <input type="submit" value="<?php _e('Gem ændringer') ?>" />
    </p>
    
    </form>
    </div>

    And the code from my home.php:

    <div class='vigtig_besked'>
    
        <span class="knapoverskrift">VIGTIGT!</span>
        <span class="knaptekst"><?php echo get_option('vigtigt_data'); ?></span>
    
    </div>

The topic ‘reset form input field’ is closed to new replies.