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'] = 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
. It must be:input[name="host_info"]
. – leymannx Jul 10 '17 at 9:15