您应该能够在您的字段上使用#states 属性来执行您所要求的操作。您可以添加多个验证,它将为您创建所有 jquery。
例如:
// 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'),
),
),
),
);