I must be missing something... This is suppose to do supplementary validation of optional profile fields. This expects common stuff like trim() and strip_tags() to have already been run. Params are passed by-ref, so I can set them to an empty string if any fail.
I thought this was correct, maybe there is an easier way to achieve this, If anyone can explain to me where I lost my way.
function validate_optional_fields(&$website, &$location, &$occupation, &$interests, &$sig, &$facebook)
{
$check_var_length = ['location', 'occupation', 'interests', 'sig', 'facebook'];
for($i = 0; $i < count($check_var_length); $i++)
{
if (strlen((string) ${$check_var_length}[$i]) < 2)
{
${$check_var_length}[$i] = '';
}
}
// website has to start with http://, followed by something with length at least 3 that
// contains at least one dot.
if ($website != "")
{
if (!preg_match('#^http[s]?:\/\/#i', (string) $website))
{
$website = 'http://' . $website;
}
if (!preg_match('#^http[s]?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', (string) $website))
{
$website = '';
}
}
return;
}