Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements hook_form_alter().
- */
- function utilities_form_alter(&$form, &$form_state, $form_id) {
- if ($form_id == 'commerce_checkout_form_checkout') {
- $form['customer_profile_billing']['field_cif_nif_id']['#states'] = array(
- // This #states rule says that the "field_cif_nif_id" fieldset should only
- // be shown if the "field_dispongo_de_" form element is set to "CIF/NIF/ID".
- 'visible' => array(
- '#edit-customer-profile-billing-field-dispongo-de-und' => array('value' => t('CIF/NIF/ID')),
- ),'required' => array(
- '#edit-customer-profile-billing-field-dispongo-de-und' => array('value' => t('CIF/NIF/ID')),
- ),
- );
- $form['#validate'][] = 'utilities_custom_validate_required_field';
- }
- }
- function utilities_custom_validate_required_field($form, &$form_state) {
- // Check if the field you want to validate exists in the form.
- // replace 'field_dispongo_de_' with the name of field you want to validate.
- if ((isset($form_state['values']['field_cif_nif_id'])) && (empty($form_state['values']['field_cif_nif_id']))) {
- form_set_error('field_cif_nif_id', 'Field cannot be left blank');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement