'; $cf7Form.find('input[name="_wpcf7"]').parent().append(fname); if(0 === data.length){ $cf7Form.trigger("cf7_2_post_96bfb6d58c", data); return false; } if(data.referrer !== undefined){ $cf7Form.c2pCF7Field("select", "referrer", data.referrer);};if(data.referrer_text !== undefined){ $cf7Form.c2pCF7Field("text", "referrer-text", data.referrer_text);};if(data.datenschutz !== undefined){ $cf7Form.c2pCF7Field("acceptance", "datenschutz", data.datenschutz);}; if(data.map_post_id !== undefined){ fname = ''; $cf7Form.find('input[name="_wpcf7"]').parent().append(fname); } /* trigger the formMapped event to let other scripts that the form is now ready */ if( $cf7Form.is('.cf7-smart-grid .wpcf7-form') && !$cf7Form.is('.cf7sg-ready') ){ $cf7Form.on('cf7SmartGridReady', function(){ $cf7Form.trigger("cf7_2_post_96bfb6d58c", data) }) }else{ $cf7Form.trigger("cf7_2_post_96bfb6d58c", data); } //console.log('cf7_2_post_96bfb6d58c form ready'); }//end preloadForm() }); //document ready //field setter for jquery form object. if(!$.isFunction( $.fn.c2pCF7Field)){ $.fn.c2pCF7Field = function(fieldType, fieldName, fieldValue){ let $form = $(this), $field = null; if(!$form.is('form.wpcf7-form')) return false; if(fieldType === null) fieldType = ''; //do we have a field if(typeof fieldName == 'string' && fieldName.length > 0 ){ let pe = new CustomEvent(`c2p-prefill-field`, { name: fieldName,value: fieldValue }); switch(fieldType){ case 'checkbox': case 'radio': fieldName = 'checkbox'===fieldType ? `${fieldName}[]` : fieldName; if(!Array.isArray(fieldValue)) fieldValue = new Array(fieldValue); $.each(fieldValue , function(index, v){ $field = $form.find(`input[name="${fieldName}"][value="${v}"]`).prop('checked',true).trigger('change'); }); break; case 'select': case 'dynamic_select': $field = $form.find(`select[name=${fieldName}]`).val(fieldValue).trigger("change"); break; case 'textarea': $field = $form.find(`textarea[name=${fieldName}]`).val(fieldValue).trigger("change"); break; case 'file': break; default: $field = $form.find(`input[name="${fieldName}"]`).val(fieldValue).trigger("change"); break; } if($field) $field.get(0).dispatchEvent(pe); } return $form; } }})( jQuery );(function( $ ) { 'use strict'; $( document).ready(function() { var fname; var $cf7Form = $("div#cf7_2_post_f5f9eb01ff form.wpcf7-form"); var $input; if($cf7Form.is('div.cf7-smart-grid.has-grid form.wpcf7-form')){ //if the smart grid is enabled, execute the loading once the grid is ready $cf7Form.on('cf7SmartGridReady', function(){ preloadForm($(this)); }); }else{ preloadForm($cf7Form); } // function to load all the data into the form function preloadForm($cf7Form){ var data = ''; if('function' == typeof $.fn.post2CF7FormData) data = $cf7Form.post2CF7FormData('cf7_2_post_f5f9eb01ff'); else if( 'undefined' != typeof window['cf7_2_post_f5f9eb01ff'] ) data = window['cf7_2_post_f5f9eb01ff']; fname = ''; $cf7Form.find('input[name="_wpcf7"]').parent().append(fname); if(0 === data.length){ $cf7Form.trigger("cf7_2_post_f5f9eb01ff", data); return false; } if(data.referrer !== undefined){ $cf7Form.c2pCF7Field("select", "referrer", data.referrer);};if(data.referrer_text !== undefined){ $cf7Form.c2pCF7Field("text", "referrer-text", data.referrer_text);};if(data.datenschutz !== undefined){ $cf7Form.c2pCF7Field("acceptance", "datenschutz", data.datenschutz);}; if(data.map_post_id !== undefined){ fname = ''; $cf7Form.find('input[name="_wpcf7"]').parent().append(fname); } /* trigger the formMapped event to let other scripts that the form is now ready */ if( $cf7Form.is('.cf7-smart-grid .wpcf7-form') && !$cf7Form.is('.cf7sg-ready') ){ $cf7Form.on('cf7SmartGridReady', function(){ $cf7Form.trigger("cf7_2_post_f5f9eb01ff", data) }) }else{ $cf7Form.trigger("cf7_2_post_f5f9eb01ff", data); } //console.log('cf7_2_post_f5f9eb01ff form ready'); }//end preloadForm() }); //document ready //field setter for jquery form object. if(!$.isFunction( $.fn.c2pCF7Field)){ $.fn.c2pCF7Field = function(fieldType, fieldName, fieldValue){ let $form = $(this), $field = null; if(!$form.is('form.wpcf7-form')) return false; if(fieldType === null) fieldType = ''; //do we have a field if(typeof fieldName == 'string' && fieldName.length > 0 ){ let pe = new CustomEvent(`c2p-prefill-field`, { name: fieldName,value: fieldValue }); switch(fieldType){ case 'checkbox': case 'radio': fieldName = 'checkbox'===fieldType ? `${fieldName}[]` : fieldName; if(!Array.isArray(fieldValue)) fieldValue = new Array(fieldValue); $.each(fieldValue , function(index, v){ $field = $form.find(`input[name="${fieldName}"][value="${v}"]`).prop('checked',true).trigger('change'); }); break; case 'select': case 'dynamic_select': $field = $form.find(`select[name=${fieldName}]`).val(fieldValue).trigger("change"); break; case 'textarea': $field = $form.find(`textarea[name=${fieldName}]`).val(fieldValue).trigger("change"); break; case 'file': break; default: $field = $form.find(`input[name="${fieldName}"]`).val(fieldValue).trigger("change"); break; } if($field) $field.get(0).dispatchEvent(pe); } return $form; } }})( jQuery );/* ]]> */