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: "your@mail.com" %></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>
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.
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.