How to set required to TRUE or FALSE based on the GIVEN #states? I have problem with the required. It does not return a required validation when I clicked submit button. What is wrong with this code?   

$form['fieldset1']['last_name'] = array(
  '#type' =&gt; 'textfield',
  '#title' =&gt; t('Last Name'),
  '#states' =&gt; array(
    'required' =&gt; array(
      ':input[name="payment_method"]' =&gt;  array('value' =&gt; array('credit', 'debit')),
    ),
  ),
  '#attributes' =&gt; array(
    'placeholder' =&gt; array('Last Name'),
  ),
);
States are used to set properties/values by javascript. The #required property is for the server-side validation, it can't be controlled using states.

You could either implement an AJAX callback on the text field change to update the required status and rebuild the form, or implement a validation handler which checks the status of the text field and throws an error if it contains text but no payment method has been selected.