How do I apply webform validation in drupal 7? -
i have webforms in drupal 7 website. want validate webform fields. webform contains phone field should accept numeric field , should contain 10 numbers only. there module or have code this.
use hook_form_alter()
apply custom validation in drupal
create module e.g. mymodule
file mymodule.module
function mymodule_form_alter(&$form, &$form_state, $form_id) { print $form_id; if($form_id=='webform_client_form_1') //change webform id according webformid { $form['#validate'][]='mymodule_form_validate'; return $form; } } function mymodule_form_validate($form,&$form_state) { //where "phone" field name of webform phone field $phoneval = $form_state['values']['submitted']['phone']; if($phoneval=='') { form_set_error('phone','please fill form field'); } // use regular expression validate it. // in above example have check if phonefield empty or not. }
if want more detail how use hook_form_alter()
visit link http://www.codeinsects.com/drupal-hook-system-part-2.html
Comments
Post a Comment