AnsweredAssumed Answered

Submitting hidden form using forms2.js never fires onSuccess

Question asked by Jorge Pinon on Nov 6, 2019
Latest reply on Nov 14, 2019 by Sanford Whiteman

UPDATE: This works when I start with a new Safari incognito window, but then when I try it again on the same window I get the same behavior described below.

 

First off, I've looked at other similar questions here and have tried those suggestions without any luck. Some of those discussions are a couple of years old so I thought a new thread is called for.

 

Essentially I'm trying to implement a hidden form submission (like this) but I can't get onSuccess to fire. I'm testing on localhost, which is what I think the problem might be.

 

I'm getting one error in devtools:


URL: http://pages.addigy.com/index.php/leadCapture/save2
URL: http://pages.addigy.com/index.php/leadCapture/save2
Status: 400 Bad Request
Source: Network
Address: 104.17.70.206:80
Initiator:
XDFrame:1:780

and the request preview makes me think that the formId is failing in that request at some point?

{
  "error": true,
  "errorCode": 400,
  "message": "{leadCapture/save2} Approved form not found: "
}

 

Here's my basic approach:

 

On the template I have a native form element with matching fields to the ones defined in the Marketo form. Then I load the Marketo form using our CNAME domain:

<script src="https://pages.addigy.com/js/forms2/js/forms2.min.js"></script>
<form id="mktoForm_1296" style="display: none;"></form>
<script>MktoForms2.loadForm("https://pages.addigy.com", "641-IKD-453", 1296);</script>

On the submit event of the form, I do some simple validation and then (this is shortened for clarity):

MktoForms2.whenReady(function (form) {

    // create account on callback event
    form.onSuccess(function(values, followUpUrl) {
        DataRequest.doRegistration().then(function(data) {
            location.href = followUpUrl;
        },function() {
            showError('Could not create your account.');
        });
        return false;
    });

    // add fields to mkto form
    var formValues = {
        FirstName: self.firstName,
        LastName: self.lastName,
        Email: self.email,
        Company: self.companyName,
        Country: self.country,
        State: self.state
    };
    form.setValues(formValues);
    form.addHiddenFields({ 'something' : 'hello' });

    // post mkto form
    form.submit();
});

As I said, the onSuccess never fires. I'm wondering if a less hacky approach is to use onSubmit anyway, since in our case the lead gen is secondary to the actual account registration, but I really still need the lead gen to work.

 

I added an onValidate function just to check whether it was returning valid (true) before the post and it was. 

Outcomes