When a user selects the radio button that equal sales it send information to the sales department which works fine.
I need when a user selects the support department that have to enter a 5 digit serial number for the device they need support on. The serial number has to be between 3 to 5 numbers only. If the serial is not 3 to 5 numbers example:
in this box if the numbers are 123 submit, if 12324 submit, if x3423 die, if 12 die, if 123456 die. also I need for to only accept numbers.
Can I do this
if($selected == 'sales') {
$body = "From: $name_field\n E-Mail: $email_field\n Address: $address\n City: $city\n State: $state\n PostalCode: $zip\n Department $selected\n How did you about us: $hear\n Country: $country\n Comments: $comment";
mail($to, $subject, $body);
header("Location: http://url/");
}
else if($selected == 'support') {
if(preg_match("/^\d{3}$|^\d{5}$/", $_POST['serial']) === 0) {
$body = "From: $name_field\n E-Mail: $email_field\n Address: $address\n City: $city\n State: $state\n PostalCode: $zip\n Department $selected\n How did you about us: $hear\n Country: $country\n Serial Number: $serial\n Comments: $comment";
mail($toa, $subject2, $body);
header("Location: http://url/");
}
else {
die('<script type="text/javascript"> alert("Serial Number is invalid");</script>');
}
}
}
You are currently having it send the email if the regex fails to match. Your regex is wrong too. There’s a few minor things too.
Try this: