El formulario jQuery envía variables de publicación adicionales AJAX

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:

add_action('wp_ajax_nopriv_jFormerForWp', 'JFormerForWP::AjaxHandler');
add_action('wp_ajax_jFormerForWp', 'JFormerForWP::AjaxHandler');

Essentially what i need to do is send in the POST request a variable called action => jFormerForWp.

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.

So to confirm, I need to modify the jQuery code to send action = jFormerForWp.

El codigo esta aqui http://www.jformer.com/download/jFormer-dev.zip with the excerpt below of where i think the request is made by the form. Many thanks, Chris

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 = $('<input type="hidden" name="jFormer" />').attr('value', encodeURI(jFormerUtility.jsonEncode(this.getData()))); // Set all non-file values in one form object
    var formIdentifier = $('<input type="hidden" name="jFormerId" value="'+this.id+'" />');
    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();
    }
},

preguntado el 28 de agosto de 11 a las 05:08

1 Respuestas

Después de este:

var formData = $('<input type="hidden" name="jFormer" />').attr('value', encodeURI(jFormerUtility.jsonEncode(this.getData()))); // Set all non-file values in one form object
var formIdentifier = $('<input type="hidden" name="jFormerId" value="'+this.id+'" />');
formClone.append(formData);
formClone.append(formIdentifier);

adjuntar:

var formExtra = $('<input type="hidden" name="action" value="jFormerForWp" />');
formClone.append(formExtra);

Respondido 28 ago 11, 09:08

Thanks Vibhu, i had been messing around with other ajax function calls, appreciate the help you have set me back on track. - Morleyc

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.