-
-
Save XTRO123/a08b7d96ea174f8a15d193f01da6f2aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| jQuery(document).ready(function(){ | |
| jQuery('#contacts_form').on('submit',function(){ | |
| form_id = $(this); | |
| jQuery.ajax({ | |
| type: 'POST', | |
| url: '/ajax/contacts', | |
| data: new FormData($(this)[0]), | |
| dataType: 'json', | |
| cache: false, | |
| processData: false, | |
| contentType: false, | |
| success: function(data) { | |
| $(form_id).find('.invalid-feedback').html(''); | |
| $(form_id).find('input,textarea').removeClass('is-invalid') | |
| if(data.status === true){ | |
| $(form_id).html(data.output) | |
| } | |
| else{ | |
| $.each(data.errors, function(index,item) { | |
| var error_text = ''; | |
| var validate_errors_types = Object.keys(item); | |
| for(var key in validate_errors_types){ | |
| var error_text = item[validate_errors_types[key]]; | |
| var field = $(form_id).find('[name="' + index + '"]'); | |
| field.addClass('is-invalid'); | |
| field.siblings('.invalid-feedback').html(error_text); | |
| } | |
| }); | |
| } | |
| } | |
| }); | |
| return false; | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment