How to validate altered forms

daryoush - August 22, 2008 - 17:18

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

You can add the #validate

j_ten_man - August 22, 2008 - 17:52

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

<?php
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.
}
?>

Thanks so much. dp

daryoush - August 25, 2008 - 17:17

Thanks so much.
dp

 
 

Drupal is a registered trademark of Dries Buytaert.