By mortenson on
Hello I am trying to validate the field "profile_rut" from the "Personal" category. With a module I build called "sitehelper"
function sitehelper_form_alter($form_id, &$form) {
if ($form_id == 'user_register' || $form_id == 'user_edit') {
$form['Personal']['profile_rut']['#validate'] = array('formvalidate_rut' => array());
}
}
function formvalidate_rut($element) {
if ($element['#value'] == "123") {
form_set_error('profile_rut', t('RUT is invalid'));
}
}
Have tried this code and many modifications for long time, but cant make it work.
What I am doing wrong?
Comments
Drupal 6?
Is this a Drupal 6 question?
Caroline
11 heavens.com
Yes it is :)
Yes it is :)
Hope this will be helpful
In Drupal 6, HOOK_form_alter takes 3 arguments [1], and to add validation to an element once must use '#element_validate' [2].
The way element validation is handled varries through Drupal core. Looking for examples, I did not find consistency.
The above validation should work.
[1] http://api.drupal.org/api/function/hook_form_alter/6
[2] http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...
Caroline
11 heavens.com
Checkbox validation
To validate checkboxes, you'll need to install this module: http://drupal.org/project/checkbox_validate
Caroline
11 heavens.com
Wujuu!!! Caroline, I
Wujuu!!!
Caroline, I apreciated so much!
I have just test it and works.
Right now is late here, so tomorrow at first hour I will study with detail your post.
thanks again!
typo
It was late for me too... A few typos... this one: "and to add validation to an element,
onceone must use '#element_validate'..."I'm glad it works :-)
Caroline
11 heavens.com
...
That is...
If you want a required checkbox to be validated you'll need that module...
You can do your own validation of course.
Caroline
11 heavens.com
...
Excellent answer.
Validate Profiles checkbox and textfields as a group
I'd created a few checkboxes and a textfield using the Profiles module.
Problem is I need to validate them (checks for filled entries) as a group.
Meaning either they check one of the boxes, or has anything entered in the textfield, it will go through.
Had been searching for hours and is still clueless where to do the modifications.
Drupal 5. Any clues?