0

I tried to validate a custom form but without success.

My form:

<div class ="shop-container">
    <h3>CLUBLOGIN</h3>
        <div class="shop-container">
        <form data-mage-init='{"validation": {}}' action="<?php echo $this->getUrl("clubshop/index/index")?>" method="post" id="clubshop-form-custom">
            <div class="club-img">
            </div>
            <div class="club-inputs">
                <div class="club-name">
                <label class="" for="email"><span>Naam</span></label><br>
                    <input name="club-name" value="" autocomplete="off" id="club-name" type="input" class="input-text" title="Naam" >
                </div>
                <div class="club-email">
                    <label class="" for="email"><span>Emailadres</span></label><br>
                    <input name="club-mail" value="" id="club-email" type="input" class="input-text" title="email" ><br>
                </div>
                <div class="club-button">
                    <br>
                    <div class="primary"><button type="submit" class="action login primary" name="send" id="send2"><span>Inloggen</span></button></div>
                </div>
            </div>
        </form>

    </div>
</div>

What I tried so far in my phtml:

<script type="text/javascript">
require([
    'jquery',
    'mage/mage'
], function($){

   var dataForm = $('#clubshop-form-custom');
   dataForm.mage('validation', {});

});
</script>

and for this method i changed my button into input but still no scuccess.

<script>
require([
  'jquery',
  'mage/mage',
], function($){
   $( "#send2" ).click(function() {        
       $('input[name="club-email"]').validation();
       if(!$('input[name="club-email"]').validation('isValid')){
           return false;
       }
   });
});
</script>

What i am doing wrong?

1 Answer 1

0

I have checked your requirement no need to add more js.

Just Add below code in input box

data-validate="{required:true, 'validate-email':true}"

Check below code

<input name="club-name"  class="input-text" data-validate="{required:true, 'validate-email':true}" >

Thanks

5
  • Thank for your answer but still not working Sep 20, 2017 at 11:28
  • I have checked its working fine :- prnt.sc/gnfuea, Do you working on any popup design
    – shyam
    Sep 20, 2017 at 11:37
  • magneto 1 or 2? Sep 20, 2017 at 11:38
  • after i deploy my form was working. thank you very much shyam Sep 20, 2017 at 11:48
  • but this works only if a refresh the page. do you know why? Sep 20, 2017 at 12:23

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.