Support » Themes and Templates » Strange submit button behavior…

  • Hi all,

    I have a custom page template, which basically displays a form, and if the form passes the validation controls, sends these data to a db table. The problem is that when I’m hitting the submit button WP is loading some other page (I don’t know which one! it’s not search or archive!!!) and not the one I’m specifying at the form (basically i want to load the same page).

    Any ideas? feel free to check the code below…

    custom template code (this is 100% correct but I’m including it just for reference)

    <?php
    /*
    Template Name: Signup page
    */
    ?>
    <?php get_header(); ?>
    <style>
    html,body {
    background:#EFEFEF;
    }
    </style>
    <div id="page">
    <div id="insidecopy">
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <div class="copycontent">
    <h2><?php the_title() ?></h2>
    <p><?php the_content(''); ?></p>
    <?php include (TEMPLATEPATH . '/signup.php'); ?>
    </div>
    <?php endwhile; else: ?>
    <?php endif; ?>

    <div id="altsidebar">
    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Page Sidebar') ) : ?>
    <div class="altsideblock">
    <h3>Configure Your Sidebar!</h3>
    <p>To remove this message, configure your sidebar widgets throught the WordPress admin control panel.</p>
    </div>
    <?php endif; ?>
    </div>
    </div>
    </div>

    <?php get_footer(); ?>

    The custom signup code (for the <?php include (TEMPLATEPATH . ‘/signup.php’); ?>)

    // Check if a person has clicked on submit.
    if(isset($_POST['submit'])) {

    $error='';//initialize $error to blank

    // Create variables from each $_POST.
    $name = $_POST['name'];
    $email = $_POST['email'];

    if(trim($email)=='') {

    $error.="<p class=\"error\">Το πεδίο email είναι υποχρεωτικό</p>";

    } else {

    if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {
    $error="<p class=\"error\">Παρακαλώ δώστε ένα valid email</p>";
    }
    }

    if($error==''){
    //Everything is ok, the form passed the validation checks

    // Create a variable containing the SQL query.
    $query = "INSERT INTO newsletter_users (name, email)
    VALUES (‘$name’, ‘$email’)”;

    // Perform the SQL query on the database.
    $result = mysql_query($query);

    // If the query failed, display an error.
    if(!$result) {
    // The dot seperates PHP code and plain text.
    echo “Your query failed. ” . mysql_error();
    } else {
    // Everything is ok. Redisrect the user to the current wordpress page
    header( ‘Location: http://www.tsevdos.com&#8217; ) ;
    }

    } else {
    ?>
    <div style=”border;1px solid #000;”>
    <form method=”post” action=”http://www.skaiwp.paperplane.gr/?page_id=35″&gt;
    <label for=”name”>Όνοματεπώνυμο: </label>
    <input type=”text” name=”name” id=”name” value=”<?php $namevalue = (isset($_POST[‘name’])) ? $_POST[‘name’] : ‘Όνοματεπώνυμο’; echo $namevalue; ?>”>
    <label for=”email”>e-mail:</label>
    <input type=”text” name=”email” id=”email” value=”<?php $emailvalue = (isset($_POST[’email’])) ? $_POST[’email’] : ‘Όνοματεπώνυμο’; echo $emailvalue; ?>”>
    <input type=”submit” name=”submit” id=”submit” value=”Submit”>
    </form>
    <?php echo “$error”; ?>
    </div>
    <?php
    }

    } else {
    //display the form
    ?>
    <div style=”border;1px solid #000;”>
    <form method=”post” action=”http://www.skaiwp.paperplane.gr/?page_id=35″&gt;
    <label for=”name”>Όνοματεπώνυμο: </label>
    <input type=”text” name=”name” id=”name” value=”Όνοματεπώνυμο”>
    <label for=”email”>e-mail:</label>
    <input type=”text” name=”email” id=”email” value=”email”>
    <input type=”submit” name=”submit” id=”submit” value=”Submit”>

    <input type=”hidden” name=”subscribe” value=”true” />
    </form>
    </div>
    <?php
    }
    ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • CodePoet

    (@design_dolphin)

    Honestly forms in WordPress are not my strongest point (yet). 😉
    Having said that.

    Two things I would check:

    1. Is pressing the submit button adding the record in your database.
    2. I am wondering if it is the name=”submit” id=”submit” that might be causing the problem. I am not sure if this is the standard name/ id used. Maybe changing it to something else might solve the problem.

    I am not sure though…

    Have you tried a search on form plugins? Maybe you can look at the code in there, if they exist, and see how they do it.

    Thread Starter Tsevdos

    (@tsevdos)

    1. No record is inserted in db
    2. I’ll try it although I don’t think it will work… I’m pretty sure WP is loading some other template when you click the submit button, but the question is way?!?!

    You can see what’s happening here !!!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Strange submit button behavior…’ is closed to new replies.