If tick box ticked force completion of text area
I have created a php form on the form there is a field called "alert" and I wan to set the form so that if the "alert" tick box is ticked them the 开发者_如何学Gouser must enter a comment why they ticked the alert box.
Here is the code I have
if (empty($_POST['tutorComment']) && $_POST['alert'] == 'YES') {
echo "You must enter a comment on the student if you tick the alert box";
exit();
}
This seems to work if I tick the box and don't enter a comment but when I tick the box and enter a comment the code still terminates here.
Any ideas where I am going wrong?
You have a typo in your code, it's tutorComments
and not tutorComment
. Anyway it would be safer if you replaced your code with:
if( !strlen($_POST['tutorComment']) && isset($_POST['alert']) ){
echo "You must enter a comment on the student if you tick the alert box";
exit();
}
Is tutorComment
the name
of your form field? I'd double check spelling, case, and that you've used it as the name
, not the id
.
精彩评论