Support » Plugins » Plugin Nube! Making a form in the admin page

  • I’m making a custom plugin for a client and am having difficulty in making the forms and how it interacts with the DB. I’ve read plugin documentations form this site but I am having trouble completely understanding them as there are amendments and some incomplete documentation. I just want to update data in the database.

    Using WP 2.8.4

    here is my code:

    add_action(‘admin_menu’, ‘res_settings_menu’);
    add_action(‘admin_init’, ‘res_settings’ );

    //for reservation settings
    function res_settings(){
    global $wpdb;
    $settingsQ = mysql_query(‘select * from ‘.$wpdb->prefix.’res_settings order by uid asc limit 1’) or die(mysql_error());
    //$setEmail = $wpdb->get_row($settingsQ);
    $setEmail = mysql_fetch_array($settingsQ);
    register_setting(‘res_options’, ‘res_email’, $setEmail[’email’]);
    register_setting(‘res_options’, ‘res_uid’, $setEmail[‘uid’]);

    function res_settings_menu(){
    add_submenu_page(‘options-general.php’, ‘Reservation Settings’, ‘Reservation Settings’, 7, __FILE__, ‘reservation_settings’);

    function reservation_settings(){
    global $wpdb;
    mysql_query(‘update ‘.$wpdb->prefix.’res_settings set email=”‘.$_POST[‘res_email’].'” where uid=”‘.$_POST[‘res_uid’].'”‘);
    $conf_update = ‘<th scope=”row”>E-mail list updated.</th>’;
    $out = ‘
    <div class=”wrap”>
    <h2>Reservation Settings</h2>
    <form method=”post” action=”‘.$_SERVER[‘REQUEST_URI’].'”>
    <table class=”form-table”>
    <tr valign=”top”>
    <tr valign=”top”>
    <th scope=”row”>E-mail: Set the E-mail or E-mails where all reservation E-mails will be sent (list of emails MUST be separated by commas).</th>
    <tr valign=”top”>
    <td><input type=”text” name=”res_email” size=”100″ value=”‘.get_option(‘res_email’).'” /></td>
    <p class=”submit”>
    <input type=”submit” class=”button-primary” value=”Update” />

    echo $out;

    I am registering settings and its data comes from DB. the settings_fields function does not seem to echo out the hidden fields and i am not sure if the get_option function does not seem to work either. on form submission $_POST does not seem to work as well. I know that the html is being outputted in a function, I think this is the main problem, moreover, I am not sure if I am creating the form correctly.

    please advise

    thanks in advance

  • The topic ‘Plugin Nube! Making a form in the admin page’ is closed to new replies.