4

I am going to add front-end validation for customer attribute by adding CSS classes 'validate-length' and 'maximum-length-xx' in the input tag.

I need to find how I can retrieve, for example, the Maximum Text Length value of customer attribute 'First Name'.

screenshot

1 Answer 1

2

This worked for me for the telephone attribute. I addapted the script for firstname, but please check it again, in case I missed something.

$firstname = Mage::getSingleton('eav/config')->getAttribute('customer', 'firstname');
$rules = $firstname->getValidateRules();
$validationClasses = array();
if (isset($rules['min_text_length'])){
    $validationClasses['validate-length'] = 1;
    $validationClasses['minimum-length-'.$rules['min_text_length']] = 1;
}
if (isset($rules['max_text_length'])){
    $validationClasses['validate-length'] = 1;
    $validationClasses['maximum-length-'.$rules['max_text_length']] = 1;
}

$class = implode(' ', array_keys($validationClasses));
//use $class in the form.

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.