Advertisement
Guest User

Untitled

a guest
Sep 29th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 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.        
  17.         $form['#validate'][] = 'utilities_custom_validate_required_field';
  18.       }
  19. }
  20.  
  21. function utilities_custom_validate_required_field($form, &$form_state) {
  22.   // Check if the field you want to validate exists in the form.
  23.   // replace 'field_dispongo_de_' with the name of field you want to validate.
  24.     if ((isset($form_state['values']['field_cif_nif_id'])) && (empty($form_state['values']['field_cif_nif_id']))) {
  25.     form_set_error('field_cif_nif_id', 'Field cannot be left blank');
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement