I have a validation if statement that checks two things primarily. First : to see if a drop down box named “why” is empty, if it is empty it will shoot an error to the front end stating we need you to give us a proper reason. That works fine. Now I have a second condition saying that if for any reason the value in the “why” drop down box is ‘Other” and if the comments box is empty then that will shoot another error. Now those two work fine, if its empty it will say ‘Please explain the nature of your visit in the comments box!’
my problem is that I am trying to have it so that the comments box is between 15 to 45 characters long. I have been fideling with this signinpage.php validation for about 20 some hours to make it exactly how I want and I just can’t get to where I want it. Any help would be lovely!
if(empty($why)) {
$errors[] = 'Please make sure to select the proper reasoning for your vistit today!';
}
elseif ($why ==='Other' && empty($comments)) {
$errors[] = 'Please explain the nature of your visit in the comments box!';
if (strlen($comments) < 15) {
$errors[] = 'Your explaination is short, please revise!';
}
if(strlen($comments) > 45) {
$errors[] = 'Your explaintion is to long, please revise!';
}
}
Indented:
if(empty($why)) {
$errors[] = 'Please make sure to select the proper reasoning for your vistit today!';
}
elseif ($why ==='Other' && empty($comments)) {
$errors[] = 'Please explain the nature of your visit in the comments box!';
if (strlen($comments) < 15) {
$errors[] = 'Your explaination is short, please revise!';
}
if(strlen($comments) > 45) {
$errors[] = 'Your explaintion is to long, please revise!';
}
}
If you copied and pasted this correctly, then your brackets are messing things up. Put all your comment validation into a single section that gets checked ONLY if
$why==="Other".