2

I am using ruby2 and rails4. I have the validation using jQuery. The validation errors are shown correctly, but when I click on submit button it does nothing though I had given the correct value for field. Can anybody please help me to solve the problem? My code is shown below. Thank you.

jQuery plugin:

http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.js
 http://ajax.aspnetcdn.com/ajax/jquery.validate/1.12.0/jquery.validate.min.js

In download.html.erb

    <%= form_tag file_download_contacts_path, :method => :post, :id => 'contact-form'  do |f| %>         
  <h3><b>Download Form</b></h3>      
  <div>   

  <div><%=  label_tag :Name  %><br />  
    <%= text_field_tag "contact[name]" , nil, placeholder: "Your Name" %></div>         
<div><%=  label_tag :Email %><br />
    <%= email_field_tag "contact[email]" , nil, placeholder: "[email protected]" %></div>
<div><%=  label_tag :Mobile %><br />
    <%= telephone_field_tag "contact[phone]" , nil, placeholder: "Your Contact No" %></div>
<div><br/><%= button_tag 'submit' %></div>
  </div>    
 <% end %>              


 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js" type="text/javascript"></script>
<script src="/assets/jquery.validate.js"></script>
<script src="/assets/jquery.validate.min.js"></script>   
<script type="text/javascript">
$(document).ready(function () {
$("#contact-form").validate({
debug: true,
rules: {
"contact[name]": {required: true, max: false, min: false},  
"contact[email]": {required: true, email: true},        
"contact[phone]": {required: true, digits: true, minlength: 10, maxlength: 10}                
}
});
});
</script>           

1 Answer 1

3

From jQuery Validation Plugin documentation

debug (default: false)

Type: Boolean

Enables debug mode. If true, the form is not submitted and certain errors are displayed on the console

Just remove the line debug: true form your validation method and you'll be okay.

Sign up to request clarification or add additional context in comments.

1 Comment

I am having 3 different pages on same sign-up form, I want to keep validating on 'Next' button(used to go to next page). But if I remove debug: true, then it will not work, because form is getting submitted on 'Next' button.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.