Hi -
I am adding a couple of extra form fields to the registration page by using form_alter hook. How can I validate the addition form items that I have added
without modifying the user.module.

Thanks,
dp

Comments

j_ten_man’s picture

You can add the #validate value to the values. For example:

function my_module_form_alter($form_id, $form_values){
  switch($form_id){
    case 'the_form_to_modify':
      $form['my_module_added_field'] = array(
        '#type'=>'textfield',
        '#title'=>t('My added field'),
        '#validate'=>array('my_module_check_element'=>array()),
      );
  }
}

function my_module_check_element($element){
  $value = $element['#value'];
  $name = $element['#name'];
  //Do your validation here.
}
daryoush’s picture

Thanks so much.
dp