[英]I want to validate after submission of the form but it also validate before submission of the form using jquery in drupal forms
在联系表格中有一个带有两个值电子邮件和电话的单选按钮我想在提交表单后验证但它也在使用dupery以drupal表单提交表单之前验证..在我的表单中,当我点击电子邮件时它显示一个电子邮件文本字段与错误和隐藏手机文本字段相似我选择手机它显示电子邮件和手机文本字段,但对于电话文本字段只显示错误的电子邮件字段它不显示错误现在我完成了这项工作什么是我的prblm是在点击提交按钮之前我更改电子邮件和电话价值它显示错误,但我想在提交表单后显示错误..
You should be able to use the #states property on your field to do what you are asking. 您应该能够使用字段上的#states属性来执行您的要求。 You can add multiple validations and it will create all the jquery for you.
您可以添加多个验证,它将为您创建所有jquery。
eg: 例如:
// Show the email field when email selected for radiofld
$form['email'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'email'),
),
),
),
);
// Show error message for phone field
$form['phoneerr'] = array(
'#type' => 'markup',
'#markup' => 'No Phone selected',
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'email'),
),
),
),
);
// Show the phone field when phone selected for radiofld
$form['phone'] = array(
'#type' => 'textfield',
'#title' => t('Phone'),
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'phone'),
),
),
),
);
// Show error message for email field
$form['emailerr'] = array(
'#type' => 'markup',
'#markup' => 'No Email selected',
'#states' => array(
'visible' => array(
array(
':input[name="radiofld"]' => array('value' => 'phone'),
),
),
),
);
if you really insist on using jquery independently then you should put it in a function and call it with an onclick/onchange attribute: 如果你真的坚持独立使用jquery,那么你应该将它放在一个函数中并使用onclick / onchange属性调用它:
$form['wayToContact'] = array(
'#type' => 'radios',
'#validated' => TRUE,
'#title' => t('Best way to contact'),
'#default_value' => 'Email',
'#options' => array('Email' => $this->t('Email'), 'Phone' => $this->t('Phone')),
'#attributes' => array(
'class' => array('required')
'onchange' => 'yourFunction(this)',
'onclick' => 'yourFunction(this)'
)
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.