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.


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


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 :