我有一个下拉列表,根据选择的内容显示各个字段,并且我知道可以用状态切换可见性,但是当我尝试使用必填项时,会显示*跨度,但实际上并不是必需的。我的意思是,即使它是“必需的”,我也可以单击“提交”,而不会收到来自drupal的错误消息。我是在做错什么,还是当前在Drupal 7.8中已解决?
$form['host_info'] = array(
'#type' => 'select',
'#title' => t("Host Connection"),
'#options' => array(
'SSH2' => t('SSH2'),
'Web Service' => t('Web Service'),
),
'#default_value' => t(variable_get('host_info', 'SSH2')),
'#description' => t("Specify the connection information to the host"),
'#required' => TRUE,
);
$form['ssh_host'] = array(
'#type' => 'textfield',
'#title' => t("Host Address"),
'#description' => t("Host address of the SSH2 server"),
'#default_value' => t(variable_get('ssh_host')),
'#states' => array(
'visible' => array(
':input[name=host_info]' => array('value' => t('SSH2')),
),
'required' => array(
':input[name=host_info]' => array('value' => t('SSH2')),
),
),
);
$form['ssh_port'] = array(
'#type' => 'textfield',
'#title' => t("Port"),
'#description' => t("Port number of the SSH2 server"),
'#default_value' => t(variable_get('ssh_port')),
'#states' => array(
'visible' => array(
':input[name=host_info]' => array('value' => t('SSH2')),
),
'required' => array(
':input[name=host_info]' => array('value' => t('Web Service')),
),
),
);
name
。一定是:input[name="host_info"]
。