har*_*aur 8 validation drupal-7 drupal-webform
我在drupal 7网站上有webforms.我想要的是验证我的webform字段.webform包含一个电话字段,该字段应接受数字字段,并且只能包含10个数字.是否有任何模块或我必须为此编码.
用于hook_form_alter()
在drupal中应用自定义验证
创建模块,例如mymodule
文件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 to you webformid
{
$form['#validate'][]='mymodule_form_validate';
return $form;
}
}
function mymodule_form_validate($form,&$form_state)
{
//where "phone" is field name of webform phone field
$phoneval = $form_state['values']['submitted']['phone'];
if($phoneval=='')
{
form_set_error('phone','Please fill the form field');
}
// Then use regular expression to validate it.
// In above example i have check if phonefield is empty or not.
}
Run Code Online (Sandbox Code Playgroud)
如果您想更详细地了解如何使用,hook_form_alter()
请访问此链接http://www.codeinsects.com/drupal-hook-system-part-2.html
归档时间: |
|
查看次数: |
12264 次 |
最近记录: |