There is a bug in the code of the check_required function of version 1.07.02 of PHPFormMail.
Suppose a form has fields called fred and fred_regex. If the value of the field fred does not match the regex, you should get the error message Required value (fred) has an invalid format.. This does not happen. You get Required value () has an invalid format..
The code uses the array $fieldname_lookup but this array only gets filled with values when there is an alias field. The code can be fixed by reusing the code that is used for the checking of non-empty fields.
So I would replace the body of the while loop of check_required with the following code (where I've replaced each tab by four underscores):
$val = trim($val);
$regex_field_name = $val . '_regex';
if (isset($fieldname_lookup[$val]))
____$field = $fieldname_lookup[$val];
else
____$field = $val;
if ((!isset($form[$val])) || (isset($form[$val]) && (strlen($form[$val]) < 1))) {
____$problem = false;
____$errors[] = '0|Required value (' . $field . ') is missing.';
} else if (isset($form[$regex_field_name])) {
____if (!eregi($form[$regex_field_name],$form[$val])) {
________$problem = false;
________$errors[] = '0|Required value (' . $field . ') has an invalid format.';
____}
____$invis_array[] = $regex_field_name;
}
I'm curious as to why this has not been spotted before.