Answer the question
In order to leave comments, you need to log in
How to make a required field in a Drupal form?
Drupal has something like this
$form['type_delivery'] = array(
'#type' => 'radios',
'#options' => array('courier' => t('Courier'), 'other' => t('Other')),
'#title' => t('Delivery type'),
'#default_value' => 'courier',
);
$form['type_delivery_other'] = array(
'#type' => 'textfield',
'#title' => t('Other delivery type'),
'#required' => true,
'#states' => array(
'visible' => array(
'input[name="type_delivery"]' => array('value' =>'other'),
),
),
);
$form['type_delivery'] = array(
'#type' => 'radios',
'#options' => array('courier' => t('Courier'), 'other' => t('Other')),
'#title' => t('Delivery type'),
'#default_value' => 'courier',
);
$form['type_delivery_other'] = array(
'#type' => 'textfield',
'#title' => t('Other delivery type'),
'#required' => true,
'#states' => array(
'visible' => array(
'input[name="type_delivery"]' => array('value' =>'other'),
),
'required' => array(
'input[name="type_delivery"]' => array('value' =>'other'),
),
),
);
Answer the question
In order to leave comments, you need to log in
hover your field validator with #element_validate
https://api.drupal.org/api/drupal/developer!topics...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question