Problem converting admin pannel to user page.

  • Unknown's avatar

    Hey everyone,

    I made a plugin that allows the administrator to add things to a specific database tabel, and also view this tabel (with the ability to remove rows).

    However, now I want to make a Page where the user can fill in a form, this form would get added to the database table, however I cannot seem to get this figured out.

    Here is the code for the form in the admin pannel:
    [code]
    <?php
    global $wpdb;

    if($_POST['aanmeldimport_hidden'] == 'Y') {
    $table_name = $wpdb->prefix . "aanmeldformulier_tuin";

    $naam=$_POST['naam'];
    $email=$_POST['email'];
    $provincie=$_POST['provincie'];
    $stad=$_POST['stad'];
    $straat=$_POST['straat'];
    $nummer=$_POST['nummer'];
    $postcode=$_POST['postcode'];
    $aantal=$_POST['aantal'];

    $wpdb->query($wpdb->prepare( // Prepare query tegen SQL Injection
    "
    INSERT INTO " . $table_name . "(naam, email, provincie, stad, straat, nummer, postcode, tuin_aantal)
    VALUES (%s, %s, %s, %s, %s, %s, %s, %d)
    ",
    $naam,
    $email,
    $provincie,
    $stad,
    $straat,
    $nummer,
    $postcode,
    $aantal
    )
    );
    }
    ?>

    <div class="wrap">
    <?php echo '<h2>Aanmeldingen Admin</h2>'; ?>

    <form name="aanmeldimport_form" method="post" action="<?php echo str_replace( '%7E', '~', $_SERVER['REQUEST_URI']); ?>">
    <input type="hidden" name="aanmeldimport_hidden" value="Y">

    <?php echo '<h4>Aanmeldformulier</h4>'; ?>
    <p><?php _e("Naam:" ); ?></br><input type="text" name="naam" size="20"></p>
    <p><?php _e("Email:" ); ?></br><input type="text" name="email" size="20"></p>
    <p><?php _e("Provincie:" ); ?></br><input type="text" name="provincie" size="20"></p>
    <p><?php _e("Stad:" ); ?></br><input type="text" name="stad" size="20"></p>
    <p><?php _e("Straat:" ); ?></br><input type="text" name="straat" size="20"></p>
    <p><?php _e("Nummer:" ); ?></br><input type="text" name="nummer" size="20"></p>
    <p><?php _e("Postcode:" ); ?></br><input type="text" name="postcode" size="20"></p>
    <p><?php _e("Aantal tuintjes:" ); ?></br><input type="text" name="aantal" size="20"></p>

    <p class="submit">
    <input type="submit" name="Submit" value="<?php _e('Submit', 'aanmeldimport_trdom' ) ?>" />
    </p>
    </form>

    <?php
    if($_POST['aanmeldimport_hidden'] == 'Y') {
    echo '<div class="updated"><p>Aanmelding toegevoegd.</p></div>';
    }
    ?>
    </div>
    [/code]

    I’ve tried it with shortcode but it didn’t work:
    [code]
    //[foobar]
    function foobar_func($atts){

    global $wpdb;

    if($_POST['aanmeldimport_hidden'] == 'Y') {
    $table_name = $wpdb->prefix . "aanmeldformulier_tuin";

    $naam=$_POST['naam'];
    $email=$_POST['email'];
    $provincie=$_POST['provincie'];
    $stad=$_POST['stad'];
    $straat=$_POST['straat'];
    $nummer=$_POST['nummer'];
    $postcode=$_POST['postcode'];
    $aantal=$_POST['aantal'];

    $wpdb->query($wpdb->prepare( // Prepare query tegen SQL Injection
    "
    INSERT INTO " . $table_name . "(naam, email, provincie, stad, straat, nummer, postcode, tuin_aantal)
    VALUES (%s, %s, %s, %s, %s, %s, %s, %d)
    ",
    $naam,
    $email,
    $provincie,
    $stad,
    $straat,
    $nummer,
    $postcode,
    $aantal
    )
    );
    }

    $html = '<div class="wrap">';
    $html .= "rn" . '<form name="aanmeldimport_form" method="post" action="' . str_replace('%7E', '~', $_SERVER['REQUEST_URI']) . '">';
    $html .= "rn" . '<h4>Aanmeldformulier</h4>';
    $html .= "rn" . '<p>Naam:</br><input type="text" name="naam" size="20"></p>';
    $html .= "rn" . '<p>Email:</br><input type="text" name="email" size="20"></p>';
    $html .= "rn" . '<p>Provincie:</br><input type="text" name="provincie" size="20"></p>';
    $html .= "rn" . '<p>Stad:</br><input type="text" name="stad" size="20"></p>';
    $html .= "rn" . '<p>Straat:</br><input type="text" name="straat" size="20"></p>';
    $html .= "rn" . '<p>Nummer:</br><input type="text" name="nummer" size="20"></p>';
    $html .= "rn" . '<p>Postcode:</br><input type="text" name="postcode" size="20"></p>';
    $html .= "rn" . '<p>Aantal tuintjes:</br><input type="text" name="aantal" size="20"></p>';
    $html .= "rn" . '<p class="submit"><input type="submit" name="Submit" value="' . translate('Submit', 'aanmeldimport_trdom') . '"></p>';
    $html .= "rn" . '</form>';
    if($_POST['aanmeldimport_hidden'] == 'Y') {
    $html .= "rn" . '<div class="updated"><p>Aanmelding toegevoegd.</p></div>';
    }
    $html .= "rn" . '</div>';

    return $html;
    }
    add_shortcode( 'foobar', 'foobar_func' );
    [/code]

    The form appears fine but when the button is pressed, nothing gets added to the database.

  • Unknown's avatar

    We provide support only for wordpress.COM hosted blogs and we cannot use form codes on our blogs.
    https://en.support.wordpress.com/code/
    https://en.support.wordpress.com/code/#html-tags

    WordPress.COM and WordPress.ORG are completely separate and have different username accounts, logins, features, run different versions of some themes with the same names, and have separate support documentation and separate support forums.

    Please read this support doc so you are aware of the differences between WordPress.COM hosted blogs and WordPress.ORG software installs. http://en.support.wordpress.com/com-vs-org/

    Also know that we provide support here only for WordPress.COM hosted blogs and no others. Our support docs apply only to WordPress.COM blogs and not to any others.

  • Unknown's avatar

    <?php e_("Oops!");?>

    Seems the code tags didn’t work, my bad.

  • Unknown's avatar

    Blogger installed plugin capability does not exist on WordPress.COM blogs and there is no upgrade you can purchase here that changes that reality. You are confusing WordPress.ORG and WordPress.COM. For that type of functionality you’d need a self-hosted site running on a paid web hosting service.
    http://en.support.wordpress.com/ftp-access/

    Plugins

  • Unknown's avatar

    My bad! Did not notice the .com, just searched for wordpress forums on google D:

  • The topic ‘Problem converting admin pannel to user page.’ is closed to new replies.