ldoozer Posted September 24, 2010 Share Posted September 24, 2010 I am using a standard form to mail script and have a few fields that I need to be required to be filled in. This is working fine until someone enters a space character in a required field, which is being let thorugh. How can I stop this? here the code for required fields - I thought the trim function in the below would have taken care of this??? // This is because I originally had it require but too many people // were used to Matt's Formmail.pl which used required instead. if ($required) $require = $required; // handle the required fields if ($require) { // seperate at the commas $require = ereg_replace( " +", "", $require); $required = split(",",$require); for ($i=0;$i<count($required);$i++) { $string = trim($required[$i]); // check if they exsist if((!(${$string})) || (!(${$string}))) { // if the missing_fields_redirect option is on: redirect them if ($missing_fields_redirect) { header ("Location: $missing_fields_redirect"); exit; } $require; $missing_field_list .= "<b><font color=\"#990000\">Missing: $required[$i]</font></b><br>\n"; } } // send error to our mighty error function if ($missing_field_list) print_error($missing_field_list,"missing"); } Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted September 24, 2010 Share Posted September 24, 2010 Trim the POST'ed values and then check for string length. An empty POST'ed value trimmed == "" (or have strlen == 0) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.