1/** 2 * Submit a formbuilder form via AJAX 3 */ 4 5jQuery(function($){ // use jQuery code inside this to avoid "$ is not defined" error 6 7 /** 8 * Things that should get returned 9 * 10 * post_id 11 * post_name 12 * 13 */ 14 15 jQuery('form.form-builder').on('submit', function (e) { 16 17 e.preventDefault(); 18 19 var $theForm = jQuery(this); 20 var $feedbackContainer = jQuery(this).next('.form-feedback'); 21 var form_data = new FormData(); 22 var nonce = jQuery(this).data( 'nonce' ); 23 var outletID = jQuery(this).data( 'outlet-id' ); 24 var postID = jQuery(this).data( 'pub-post-id' ); 25 var formID = jQuery(this).data( 'form-id' ); 26 27 form_data.append('nonce', nonce); 28 form_data.append('action', 'formbuilder_ajax_handler'); 29 form_data.append('outlet_id', outletID); 30 form_data.append('post_id', postID); 31 form_data.append('form_id', formID); 32 33 // Get all the available sections and associated fields 34 var form_sections = []; 35 36 $(this).find('[data-form-section]').each(function(index){ 37 38 let section_name = $(this).data('section-name'); 39 let section_fields = []; 40 41 $(this).find('[data-form-field]').each(function(index){ 42 43 const form_field = {key: $(this).data('field-name'), label: $(this).data('field-label'), value: $(this).val()}; 44 45 section_fields.push(form_field); 46 47 }); 48 49 const form_section = {name: section_name, fields: section_fields}; 50 51 let form_section_json = JSON.stringify(form_section); 52 53 form_sections.push(form_section_json); 54 55 }); 56 57 form_sections = JSON.stringify(form_sections); 58 59 form_data.append('form_sections', form_sections); 60 61 $.ajax({ 62 url: ajax_url, 63 type: 'post', 64 contentType: false, 65 processData: false, 66 data: form_data, 67 success: function (response) { 68 69 console.log(response); 70 $theForm.hide(); 71 $feedbackContainer.show(); 72 73 if (response.data) { 74 75 76 77 } 78 79 }, 80 error: function (response) { 81 console.log('error'); 82 // console.log(response); 83 } 84 85 }); 86 87 }); 88 89 90});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.