1

I am using clientside validation along with the field UI module in a Drupal 7 site to request some custom input fields on user registration. I need to set some custom error messages using the clientside validation modulename_clientside_validation_rule_alter() function. The problem is, the field UI module creates fields with brackets in the name attribute like so: field_first_name[und][0][value]. When I use this as the first argument of _clientside_validation_set_required(), the proper error message is not being shown. I believe this is because the brackets are not seen as part of the string. How can I make the brackets literally brackets and not look like an array to drupal?

1 Answer 1

1

The problem wasn't the brackets—I was able to set the rule by referencing the nested #name and #value keys:

_clientside_validation_set_required(
      $element['field_first_name']['und']['0']['value']['#name'],
      $element['field_first_name']['und']['0']['value']['#title'],
      isset($element['field_first_name']['und']['0']['value']['#required']) ? $element['field_first_name']['und']['0']['value']['#required'] : FALSE,
      $js_rules,
      t('Please enter your @field_name.', array('@field_name' => strtolower($element['field_first_name']['und']['0']['value']['#title'])))
    );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.