- This topic is empty.
-
AuthorPosts
-
April 2, 2010 at 8:21 pm #28614
ponyack
ParticipantHi,
I was using the PHP contact form that I download from CSS Tricks. When the user clicks submit in Opera or Chrome it submits the form even if the text fields are blank –
Any help with this would be appreciated
John
April 3, 2010 at 7:46 am #73390Irrorate
MemberTo make sure all the fields have a value, you’d need to run something like:
Code:if(empty($_POST[‘name’]) || empty($_POST[’email’]) || empty($_POST[‘comments’])){
//run code here
die()
} else {
//continue with validation
}That basically says "if a field is empty, run code & die (stop processing), else continue with validation"
April 5, 2010 at 10:53 am #73536ponyack
ParticipantHi,
Thanks for the relpy. That makes sense but I am not so versed with PHP, so I am not sure how to get the code to work. Could you help me with getting the validation to work?
Below is the code that I am using right now
John
Code:“);// redirect to success page
// CHANGE THE URL BELOW TO YOUR “THANK YOU” PAGE
if ($success){
print ““;
}
else{
print ““;
}
?>April 6, 2010 at 11:47 am #73560Irrorate
MemberCode:$value){
if(empty($value)){
echo “You have left the ” . $key . ” field blank.”;
die();
}
}// send email
$success = mail($EmailTo, $Subject, $Body, “From: <$EmailFrom>“);// redirect to success page
// CHANGE THE URL BELOW TO YOUR “THANK YOU” PAGE
if ($success){
print ““;
}
else{
print ““;
}
?>That should work. It is untested, but try it and get back to me.
April 6, 2010 at 1:35 pm #73569ponyack
ParticipantHi,
That works great.
I just realized that the PHP form has a bunch of JavaScript that is supposed to do the validation.
This is a link – its the second form https://css-tricks.com/downloads/php-stuff/
Anyway – thanks for the help – if you have time, I have a style quesiton – When the warning happens is there a way to create that on the same page or at least a pop up –
John
April 6, 2010 at 2:59 pm #73324Irrorate
Member"ponyack" wrote:Hi,That works great.
I just realized that the PHP form has a bunch of JavaScript that is supposed to do the validation.
This is a link – its the second form https://css-tricks.com/downloads/php-stuff/
Anyway – thanks for the help – if you have time, I have a style quesiton – When the warning happens is there a way to create that on the same page or at least a pop up –
John
Hey ponyack,
You would either have to use JavaScript to validate the fields (but if JS is disabled, that will fail) or you’re going to have to use AJAX to check for the PHP reply and show it on the screen. Both of which I don’t have much experience in :p
April 8, 2010 at 10:14 am #73680ponyack
ParticipantHi,
Thanks for the help, I have found another PHP script that does a good job of validation.
John
-
AuthorPosts
- The forum ‘Back End’ is closed to new topics and replies.