Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. /**
  2.  * Implements hook_form_alter().
  3.  */
  4. function utilities_form_alter(&$form, &$form_state, $form_id) {  
  5.     if ($form_id == 'commerce_checkout_form_checkout') {  
  6.        
  7.         $form['customer_profile_billing']['field_cif_nif_id']['#states'] = array(
  8.           // This #states rule says that the "field_cif_nif_id" fieldset should only
  9.           // be shown if the "field_dispongo_de_" form element is set to "CIF/NIF/ID".
  10.             'visible' => array(
  11.                 '#edit-customer-profile-billing-field-dispongo-de-und' => array('value' => t('CIF/NIF/ID')),
  12.             ),'required' => array(
  13.                 '#edit-customer-profile-billing-field-dispongo-de-und' => array('value' => t('CIF/NIF/ID')),
  14.             ),        
  15.         );
  16.         $form['buttons']['continue']['#validate'][]  = 'utilities_custom_validate_required_field';
  17.     }
  18. }
  19. /**
  20.  * Callback handling the custom validation.
  21.  */
  22. function utilities_custom_validate_required_field($form, &$form_state) {
  23.       if ((isset($form_state['values']['customer_profile_billing']['field_cif_nif_id'])) && empty($form_state['values']['customer_profile_billing']['field_cif_nif_id']['und'][0]['value'])
  24.       ) {
  25.              dpm($form_state['values']);
  26.          form_set_error('customer_profile_billing[field_cif_nif_id][und][0][value', t('Field cannot be left blank'));
  27.       }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement