I am completely stumped with this (that, or I've just been staring at it for too long that there is an obvious error and I can't see it)
I've got a simple form which validates on the same page which is a custom template I have made
<form action="" method="post">
<input type="text" id="name" name="name" placeholder="Please enter your full name" />
<input type="email" id="email" name="email" placeholder="Please enter your email address" />
<input type="hidden" name="newsletterform" value="newsletterform" />
<input class="submit" type="submit" name="submit" id="searchsubmit" value="submit" />
</form>
It is then validated like so
<?php
$formsubmitted = (!empty($_POST['newsletterform'])) ? $_POST['newsletterform'] : "";
if($formsubmitted !== ''){
$fullname = (!empty($_POST['name'])) ? $_POST['name'] : "";
$email = (!empty($_POST['email'])) ? $_POST['email'] : "";
$failed = '';
if (empty($fullname)){
$failed.= 'Please enter your name.<br />';
}
if (empty($email)){
$failed.= 'Please enter your email address.<br />';
}
}
if ($failed == '' and $formsubmitted !== ''){ ?>
<div id="success-title">
Thank you for signing up!
</div>
<?php
}
if ($failed !== '' and $formsubmitted !== '') { ?>
<div id="error-title">
Sorry, we could not accept the details you submitted to us. Please see below.
</div>
<div id="error-body">
<?php echo $failed;?>
</div>
<?php } ?>
It shows the errors when you try to send an empty form, it validates the email fine when there is a value in there and when the name field is empty. When something is entered into the name field when there is something or nothing in the email field it goes to my 404 page.
You can do this --
The solution is very simple, avoid using in forms the
name
attribute called "name".change:
to:
Additional info:
Unsafe Names for HTML Form Controls
For me it works fine in this way, try replace your PHP with this: