How to make a form element required with states ?

So the problem is when you try to make a field required using ‘states’ , it is not getting validated because everything happens in the browser (client side), nothing get validated on server side. So if you try this code.

<code>

‘required’ => array(
‘:input[name=”save_settings”]’ => array(‘checked’ => TRUE),
),

</code>

This will add the red asterisk to the form element but it will not get validated. So the solution is

You need to add custom validation in hook_form_validate function.

Reference : https://api.drupal.org/api/examples/form_example%21form_example_states.inc/function/form_example_states_form/7

https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_process_states/7#comment-16909