Make a field non-mandatory but with parameters

The following code works great if it’s mandatory. Everything I have tried to get it to work as a non-mandatory field, locks the form it’s in. Any suggestions?

$state = check_input($_POST[‘inputState’], “Please enter your State”);
$state = strtoupper($state);
/* If state has non alphabetical characters show error message */
if (!preg_match("/^[a-zA-Z]{2}$/", $state)) {
show_error(“State abbreviation must have two Alphabetical Characters, only.”);
}

Thanks for the help,
honey

[php]// check if state was passed in first
if(isset($_POST[‘inputState’])) {
$state = check_input($_POST[‘inputState’], “Please enter your State”);
$state = strtoupper($state);
/* If state has non alphabetical characters show error message */
if (!preg_match("/^[a-zA-Z]{2}$/", $state)) {
show_error(“State abbreviation must have two Alphabetical Characters, only.”);
}
}[/php]

This answer allows the form to be processed but does not catch that only one or more than 2 characters were entered and it does not show any results in the email that is sent to the website owner.

All this does, is allow validation to be run only if the abbreviation is submitted, which is what you asked about. I didn’t create the validation parameters, you added that. Nor did you mention anything about showing results or anything about an email. So, what were you expecting?

Sponsor our Newsletter | Privacy Policy | Terms of Service