By rodrigo21 on
Hello,
I am trying to create a very simple module called sitehelper ( using drupal 6.1) for adding validation to a field in the registration proces. The field name is profile_rut, and its category is "Personal Information"
I have been trying for many days (I am a newbie) but I can't make it work. Here is the sitehelper.module file simplified for make it easy to detect any error.
//intercept user_register and user_edit forms and add validation function for profile_rut
function sitehelper_form_alter($form_id, &$form) {
if ($form_id == 'user_register' || $form_id == 'user_edit')
$form['Personal Information']['profile_rut']['#validate'] = array('sitehelper_profile_rut_validate' => array());
}
//function for validating the profile_rut field. Simplified for this example
function sitehelper_profile_rut_validate($element) {
if ( $element['#value'] == ' ')
form_set_error('profile_rut', t('This is not a valid RUT'));
}
Dont matter what condition I use, it let me register with any value in the profile_rut, and the 'This is not a valid RUT' string never shows up.
Any help will be very appreciated
Comments
Use validate_hook instead
Rodrigo,
You may use hook_validate instead. Have in mind the node type to do this. sitehelper_node_form_validate:
Another way is setting the function that validates in the hook_form:
A tip: check validation using:
This will print the content of the array.
Cualquier cosa preguntame en español a ver si te puedo ayudar
Slds
Juan: muchas gracias por tu
Juan: muchas gracias por tu respuesta
Para usar la funcion sitehelper_node_form_validate, estoy perdido en que parametros usar, no sabria si usar los mismos ya que no se que significan($form_id, $form_values), a pesar de haber estudiado la funcion en API. Tampoco se por que no esta el campo validar en los parametros(en mi caso seria profile_rut creo)
Para usar hook_form no se en que momento le digo a la funcion el campo que estoy validando, tampoco se como meter mi funcion de validacion en un array.
gracias denuevo.
Sustainable Transport in Drupal.
www.ridebubble.org
www.nosfuimos.cl
Intente cambiar el codigo de
Intente cambiar el codigo de mi sitehelper.module por :
pero no pasa nada, lo unico es que me sale una pagina en blanco cuando hago un logout.
Sustainable Transport in Drupal.
www.ridebubble.org
www.nosfuimos.cl
try to change the code of my
try to change the code of my sitehelper.module by :
but still nothing happens