简体   繁体   中英

How do I get my form to submit using parsley.js?

I've gotten the validation to work and the message appear on submit, however the page doesn't seem to process the form/refresh. Otherwise I think I am good to go!

This my html:

<form  parsley-validate id="frmContact" action="<?php echo $_SERVER['PHP_SELF']; ?>"                           method="POST">
<p>
<label for="yourName">name</label>
<input id="yourName" parsley-required="true" parsley-mincheck="2" parsley-focus="first"  type="text" name="name" class="required textArea" placeholder="Please enter your full name"/>
</p>

<p>
<label for="email" >Email</label> 
<input id="email" data-trigger="change" parsley-required="true" parsley-type="email"  type="email" name="email" class="textArea" placeholder="Please enter your email address"/>
</p>

<p>
<label for="comments">Comments</label> 
<textarea id="comments" data-trigger="change" required data-required="true" name="comments"  class="textArea" title="Message field!"/>
</textarea>
</p>

<p>
<input type="submit" class="submit myButtons submitButton specificLink button button-block button-rounded button-large" name="submit" value="Submit" placeholder="">
</p>

<div id="results" class="results" style="text-align:center;">
<span>
<p class="success">Your message was sent succssfully!<br> I will be in touch as soon as I can.
</p>
</span>
</div>
</form>

js/jquery:

var dd= $.noConflict();

dd(function() { 
  dd(":text:first").focus();
    dd(".success").hide();
      dd('#frmContact').submit(function(e) { 
          e.preventDefault();
          if ( dd(this).parsley('validate') ) {
              dd.post("index.php",  dd(".success").show());       
          }
    });
}); 

Try replacing dd(this).parsley('validate') with true and false to eliminate parsley.js from the problem.

You may then notice that e.preventDefault(); does not work as you want it to. See this answer for more details.

Try this instead of your code:

dd(function() { 
  dd(":text:first").focus();
  dd(".success").hide();
  dd('#frmContact').submit(function(e) { 
    if ( dd(this).parsley('validate')) {
      dd.post("index.php",  dd(".success").show());       
    }
    return false;
  });
});

Here is a fiddle .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM