Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery Form send additional post variables AJAX
    text
    copied!<p>Hi i am integrating the jFormer library into Wordpress and hitting a snag with Ajax calls into WordPress. I have registered my Ajax handers in the WordPress plugin below:</p> <pre><code>add_action('wp_ajax_nopriv_jFormerForWp', 'JFormerForWP::AjaxHandler'); add_action('wp_ajax_jFormerForWp', 'JFormerForWP::AjaxHandler'); </code></pre> <p>Essentially what i need to do is send in the POST request a variable called action => jFormerForWp.</p> <p>The problem is my jQuery skills are limited, I have asked the devs and they may get back to me when they are able but thought I would open this up to the general jQuery community in hope they can help.</p> <p>So to confirm, I need to modify the jQuery code to send action = jFormerForWp.</p> <p>The code is here <a href="http://www.jformer.com/download/jFormer-dev.zip" rel="nofollow">http://www.jformer.com/download/jFormer-dev.zip</a> with the excerpt below of where i think the request is made by the form. Many thanks, Chris</p> <pre><code>submitForm: function(event) { var self = this; // Use a temporary form targeted to the iframe to submit the results var formClone = this.form.clone(false); formClone.attr('id', formClone.attr('id')+'-clone'); formClone.attr('style', 'display: none;'); formClone.empty(); formClone.appendTo($(this.form).parent()); // Wrap all of the form responses into an object based on the component jFormComponentType var formData = $('&lt;input type="hidden" name="jFormer" /&gt;').attr('value', encodeURI(jFormerUtility.jsonEncode(this.getData()))); // Set all non-file values in one form object var formIdentifier = $('&lt;input type="hidden" name="jFormerId" value="'+this.id+'" /&gt;'); formClone.append(formData); formClone.append(formIdentifier); this.form.find('input:file').each(function(index, fileInput) { if($(fileInput).val() != '') { // grab the IDs needed to pass var sectionId = $(fileInput).closest('.jFormSection').attr('id'); var pageId = $(fileInput).closest('.jFormPage').attr('id'); //var fileInput = $(fileInput).clone() // do find out the section instance index if($(fileInput).attr('id').match(/-section[0-9]+/)){ var sectionInstance = null; var section = $(fileInput).closest('.jFormSection'); // grab the base id of the section to find all sister sections var sectionBaseId = section.attr('id').replace(/-section[0-9]+/, '') ; sectionId = sectionId.replace(/-section[0-9]+/, ''); // Find out which instance it is section.closest('.jFormPage').find('div[id*='+sectionBaseId+']').each(function(index, fileSection){ if(section.attr('id') == $(fileSection).attr('id')){ sectionInstance = index + 1; return false; } return true; }); fileInput.attr('name', fileInput.attr('name').replace(/-section[0-9]+/, '-section'+sectionInstance)); } // do find out the component instance index if($(fileInput).attr('id').match(/-instance[0-9]+/)){ // grab the base id of the component to find all sister components var baseId = $(fileInput).attr('id').replace(/-instance[0-9]+/, '') var instance = null; // Find out which instance it is $(fileInput).closest('.jFormSection').find('input[id*='+baseId+']').each(function(index, fileComponent){ if($(fileComponent).attr('id') == $(fileInput).attr('id')){ instance = index + 1; return false; } return true; }); fileInput.attr('name', $(fileInput).attr('name').replace(/-instance[0-9]+/, '-instance'+instance)); } $(fileInput).attr('name', $(fileInput).attr('name')+':'+pageId+':'+sectionId); $(fileInput).appendTo(formClone); } }); // Submit the form formClone.submit(); formClone.remove(); // Ninja vanish! // Find the submit button and the submit response if(!this.options.debugMode){ this.controlNextButton.text(this.options.submitProcessingButtonText).attr('disabled', 'disabled'); } else { this.form.find('iframe:hidden').show(); } }, </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload