I'm trying to send a form from a modal and also an image from that form.

the form_data works fine with only serialize(), but I need to attach the image to data, so I did this:

   click: function (data) {
                    var form_data = new FormData();
                    var form = $("#bss-refund-form").serialize();

                    form_data.append('form', form);
                    $.each($('#evidence')[0].files, function(i, file) {
                        form_data.append('evidence', file);


                    if($('#bss-refund-form').valid()) {

                            showLoader: true,
                            url: url,
                            type: 'POST',
                            data: form_data,
                            processData: false,
                            contentType: false
                            .done(function () {
                                console.log("ok" + form_data);

                            .fail(function () {
                                console.log("bad" + form_data);

in the Controller here is the form_key validation.

if (!$this->formKeyValidator->validate($this->getRequest())) {
            $this->messageManager->addErrorMessage("Invalid request!");
            return $resultRedirect->setPath('customer/account/');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.