0

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()) {
 $.ajax({
 showLoader: true,
 url: url,
 type: 'POST',
 data: form_data,
 processData: false,
 contentType: false
 })
 .done(function () {
 $("#bss-refund-modal").modal('closeModal');
 $("#bss-refund-form")[0].reset();
 location.reload(true);
 console.log("ok" + form_data);
 })
 .fail(function () {
 $("#bss-refund-modal").modal('closeModal');
 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/');
 }
asked Nov 23, 2020 at 0:53

1 Answer 1

0

I had this issue, and my problem was the wrong domain set in table core_config_data on path "web/cookie/cookie_domain". Check this config has the right value for your domain.

https://support.hypernode.com/en/troubleshooting/performance/how-to-fix-invalid-form-key-error

answered Sep 22, 2021 at 16:10

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.