Fields created by the profile module and marked to be included on the registration form (user/register) are not validated by the profile module. Therefore, the only validation done is form API required field validation.
This can easily be tested by adding a profile URL type field that is marked to appear on registration. If you enter a bogus value that is not an URL is will pass validation (or that is, the valid_url validation in profile.module will be skipped). This appears to be related to the overall way 'register' fields are special cased and the account category system. On user register all values are passed under the 'account' category and not the category the profile fields belong to.
The proper handling does happen on user/X/edit/CATEGORY so this is only applies to 'register' profile fields during user/register.
function profile_validate_profile($edit, $category) {
$result = _profile_get_fields($category);
while ($field = db_fetch_object($result)) {
if ($edit[$field->name]) {
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' => $field->title)));
}
}
}
else if ($field->required && !user_access('administer users')) {
form_set_error($field->name, t('The field %field is required.', array('%field' => $field->title)));
}
}
return $edit;
}
I'm thinking about a patch but the biggest problem I see is that hook_user validate op in profile.module can't cleanly distinguish when its a register vs. and edit.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 328612_9.patch | 504 bytes | janusman |
| #2 | 328612.patch | 694 bytes | dldege |
Comments
Comment #1
dldege commentedThe same issue exists in D5.12
Comment #2
dldege commentedHere is the fix but I don't like it - I hate path specific fixes. The profile category and register system seems a bit flaky
Comment #3
dldege commentedComment #4
Alaska commentedIs there a suggested fix for version 5.14?
Have the same issue. An added phone field will not validate. It is name=profile_phone.
Comment #5
neil.david commentedYep I have the same issue.
When a new user registers and puts www.example.com on the URL field(profile I added), the link that's created on his/her profile becomes http://www.drupal-site.com/www.example.com.
I'm using Drupal 6.11.
Comment #6
ingo86 commentedThis bug exists on drupal 6.14 too.
URL profile field is not validated during the registration (hook validate is not called).
Ingo86 & Psicomante
Comment #7
janusman commentedThis seems fixed in D7. Looks a lot like the patch in #2.. so marking RTBC.
Comment #9
janusman commentedNew patch.
Comment #11
janusman commentedHuh, that doesn't seem right. Changing the version an re-setting to needs review.
Comment #12
janusman commented#9: 328612_9.patch queued for re-testing.
Comment #13
janusman commentedSetting back to RTBC for the reasons mentioned in #7. Above path is just a re-roll so it applies to 6.x.
Comment #14
gábor hojtsySo the Drupal 7 code does indeed do something similar but much more generic, see http://api.drupal.org/api/drupal/modules--profile--profile.module/functi...
It took some time to me to realize that _profile_get_fields() does indeed ignore category if the register argument is set. Pretty obscure...
Anyway, regarding the patch itself, checking for $_GET['q'] seems to be pretty obscure. First of all, the registration form is displayed in different flows in Drupal, such as the OpenID module flow, which I believe displays it under a different URL. And anyway, contrib modules might just drupal_get_form() the registration form for other reasons (see dialog module displaying it in a popup for example). So checking for the path of the page does seem very limiting. Do we have any information or can get any information to check for the form being handled vs. the page? Like in Drupal 7. That would be much more robust, and we'd not need to special case a URL that is not always true.