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 INTOnewsletter_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: https://www.tsevdos.com’ ) ;
}} else {
?>
<div style=”border;1px solid #000;”>
<form method=”post” action=”https://www.skaiwp.paperplane.gr/?page_id=35″>
<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=”https://www.skaiwp.paperplane.gr/?page_id=35″>
<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
}
?>
- The topic ‘Strange submit button behavior…’ is closed to new replies.