3

Validate Multiple Custom Forms on same PHTML file.

I have 3 forms on same phtml file i trying to validate the input fields. One time one form is shown

Sign In { if successful} WriteReview { otherwise } signup

Custom js is also triggered on click of submit, but I want to do this with Magento validations.

In /var/www/html/magento16/app/design/frontend/base/default/template/reviewrating/signupformhb.phtml''

 <form method="POST" action="#/" accept-charset="UTF-8" id="hb_user_login" onsubmit="event.preventDefault(); user_login();" class="form-horizontal" enctype="multipart/form-data" novalidate="novalidate">

 <input required="" id="email" name="email" type="email" class="required-entry validate-email" value="" aria-required="true"> 

.................. ...

 <form method="POST" action="#/" accept-charset="UTF-8" id="hb_user_signup" onsubmit="event.preventDefault(); user_login();" class="form-horizontal" enctype="multipart/form-data" novalidate="novalidate">

 <input required="" id="email" name="email" type="email" class="required-entry validate-email" value="" aria-required="true"> 

.................. ... ........

<script type="text/javascript">
//<![CDATA[


        var dataFormLOGIN = new VarienForm('hb_user_login', true);
        var dataFormSIGNUP = new VarienForm('hb_user_signup', true);

//]]>
</script> 

As @Piyush sir told that it validates form before submmiting what i am little bit confused that if i create two seprate objects of VarienForm (VIZ dataFormLOGIN & dataFormSIGNUP why magento mix ids of two different forms ?

Issue: validation work on few fields only not in all fields

8
  • you have to set input name/id different for both the forms – Piyush Dec 20 '17 at 13:32
  • means name="form1Email" and name="form2Email" ? – inrsaurabh Dec 20 '17 at 13:34
  • Yes , try changing id first, if its still same then try changing name too – Piyush Dec 20 '17 at 13:36
  • sir if i change id or class than i have to make changes in other validations as well, and there are third party API s as well. – inrsaurabh Dec 20 '17 at 13:41
  • Magento validations works based on id, So if you have duplicate id for input then it will display validation message for the first field only – Piyush Dec 20 '17 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.