I have a drop down list that displays various fields based on what is chosen and I know that I can toogle the visibility with states but when I try to use required the * span is display but it isn't actually required. What I mean is that even though it's "required" I can hit submit and not get an error message from drupal. Am I doing something wrong or is this currently broken in Drupal 7.8?
$form['host_info'] = [
'#type' => 'select',
'#title' => t("Host Connection"),
'#options' => [
'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'] = [
'#type' => 'textfield',
'#title' => t("Host Address"),
'#description' => t("Host address of the SSH2 server"),
'#default_value' => t(variable_get('ssh_host')),
'#states' => [
'visible' => [
':input[name=host_info]' => ['value' => t('SSH2')],
],
'required' => [
':input[name=host_info]' => ['value' => t('SSH2')],
],
],
];
$form['ssh_port'] = [
'#type' => 'textfield',
'#title' => t("Port"),
'#description' => t("Port number of the SSH2 server"),
'#default_value' => t(variable_get('ssh_port')),
'#states' => [
'visible' => [
':input[name=host_info]' => ['value' => t('SSH2')],
],
'required' => [
':input[name=host_info]' => ['value' => t('Web Service')],
],
],
];
name
and you must not uset()
for the value. It should be':input[name="host_info"]' => ['value' => 'SSH2'],