Optional field URL in Profile module is being difficult
PeterLucas - October 7, 2005 - 20:55
I made a field to let users give their website address on the registration page. I tried it with 'www.cnn.com' and got this:
The value provided for Website is not a valid URL.
So the system wants me to put in 'http://www.cnn.com'. I know that's a correct URL, but the average user doesn't give a f*** about http:// and may not even understand what went wrong.
Is there a more idiot proof way to handle this? Is there a way to let the system recognize web addresses both with and without http://?

profile.module
When you open profile.module you'll see in the profile_validate_profile function the code
if ($field->type == 'url') {if (!valid_url($edit[$field->name], true)) {
form_set_error($field->name, t('The value provided for %field is not a valid URL.', array('%field' => theme('placeholder', $field->title))));
}
}
If you change the code !valid_url($edit[$field->name], true) to !valid_url($edit[$field->name], false); this tests for relative URLs. The problem you have then is that you have a URL relative to your site. So you should check for http:// at the start of the string and tack it on when it's absent. Do this before the inner IF.
Alternatively you can modify the error; 'The value provided for Website is not a valid URL. URL's should begin with http://'
Good luck.
PS If you mask your swearing with *, you may just as well omit it entirely (...doesn't care about...).
Welll...
What if the user enters http:// but it's still an invalid URL?
The error message needs to be more complete, saying what the problem is, yes.
- David Herron - http://7gen.com/