I am new to jquery and I am editing a website form. In the form it has something like this
- var handleRegister = function () {
- ....
- ...
- ...
- $('.register-form').validate({
- errorElement: 'span', //default input error message container
- errorClass: 'help-block', // default input error message class
- focusInvalid: false, // do not focus the last invalid input
- ignore: "",
- rules: {
-
- fullname: {
- required: true
- },
- email: {
- required: true,
- email: true
- },
- tnc: {
- required: true
- }
- },
- messages: { // custom messages for radio buttons and checkboxes
- tnc: {
- required: "Please accept TNC first."
- }
- },
- invalidHandler: function (event, validator) { //display error alert on form submit
- },
- highlight: function (element) { // hightlight error inputs
- $(element)
- .closest('.form-group').addClass('has-error'); // set error class to the control group
- },
- success: function (label) {
- label.closest('.form-group').removeClass('has-error');
- label.remove();
- },
- errorPlacement: function (error, element) {
- if (element.attr("name") == "tnc") { // insert checkbox errors after the container
- error.insertAfter($('#register_tnc_error'));
- } else if (element.closest('.input-icon').size() === 1) {
- error.insertAfter(element.closest('.input-icon'));
- } else {
- error.insertAfter(element);
- }
- },
- submitHandler: function (form) {
- form.submit();
- }
- });
- $('.register-form input').keypress(function (e) {
- if (e.which == 13) {
- if ($('.register-form').validate().form()) {
- $('.register-form').submit();
- }
- return false;
- }
- });
- }
As far as i can make out from this code is that it validates the form and if no error found it submits the form as per form action. Instead of this i would like to submit the form through jquery and process the form in php page and revert back if error found and display the error.