I was building an email script that would be simple for any non-technical person to use and I was running through a loop to build the email content and also to test and see if a required field was not filled in. I needed a way to see if the value of a variable was in a comma delimited list, so I quickly found the strpos function which allowed me to finish a small project. This code can be modified to grab all the variables in the url string by changing the HTTP_POST_VARS to HTTP_GET_VARS.
<?
$required_list = "name,lastname,submit_by,phone,comments";
$form_fields = array_keys($HTTP_POST_VARS);
for ($i = 0; $i < sizeof($form_fields); $i++) {
$thisField = $form_fields[$i];
$thisValue = $HTTP_POST_VARS[$thisField];
$pos = strpos($required_list, $thisField);
if ($pos == true) {
if( trim($thisValue) == ""){
$error_list .= "<BR><font style=\'color:gray;font-weight:bold\'>" . $thisField . "</font> is a required field.";
}
}
$email_content = "<br>".$thisField." : ".$thisValue;
}
?>