1

I'm struggling to find what I'm doing wrong in this process, and I kindly ask for your suggestions. The goal is : To have a minimum text for the products reviews. In a previous question I received the suggestion to use jquery, but looking around seems that it could lead to some conflicts. so I prefer to use the Magento form validation, both for speed and compatibility. What I've done: Looking at the validation.js file I've foun that there is a validation that could do the trick. using this :

['validate-length', 'Text length does not satisfy specified text range.', function (v, elm) {
                var reMax = new RegExp(/^maximum-length-[0-9]+$/);
                var reMin = new RegExp(/^minimum-length-[0-9]+$/);
                var result = true;
                $w(elm.className).each(function(name, index) {
                    if (name.match(reMax) && result) {
                       var length = name.split('-')[2];
                       result = (v.length <= length);
                    }
                    if (name.match(reMin) && result && !Validation.get('IsEmpty').test(v)) {
                        var length = name.split('-')[2];
                        result = (v.length >= length);
                    }
                });
                return result;
            }],

I modified the file "form.phtml" in

app/design/frontend/default/MYTEMPLATE/template/review

adding the class after class="required-entry" , so basically , right now the review details text-area looks like:

<li>
   <label for="review_field" class="required"><em>*</em><?php echo $this->__('Review') ?></label>
    <div class="input-box">
    <textarea  name="detail" id="review_field" cols="5" rows="3" class="required-entry validate-length maximum-length-600 minimum-length-150"><?php echo $this->htmlEscape($data->getDetail()) ?></textarea>
     </div>
</li>

What is happening is ....NOTHING. just as if I didn't do any changes. I also tried to add a custom class in the validation.js file , using this code:

['validate-revminlength', 'Minimum 150 characters are needed.', function (v, elm) {

if(v.length < 150)
{
return false;
}
else
{
return true;
}
}], 

and then adding the class validate-revminlength just after required-entry. No changes at all. reviews are still sent even with 2 letters. the strange behaviour is also that if I try to remove the class "required-entry" or if I add something different just like "test" it seems to still work as if nothing has changed. What do I miss? What should I check ?

1 Answer 1

2

May be it's not relevant anymore for you but this may help to anyone else. I had similar task and fronend validation didn't work for review form. Finally I found that the reason was simply duplicated 'id' value. I.e. there was added 'a' element with the same 'id' attribute as review 'form'. It prevented validation. After removing that duplicate validation works flawlessly.

Your Answer

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

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