AnsweredAssumed Answered

Form. On Success CallBack not firing on Iphone

Question asked by Anthony Zhu on Jun 3, 2019
Latest reply on Jun 4, 2019 by Anthony Zhu

Hello,

 

Sanford Whiteman

 

Here is a link to a sign up form. We have our marketo form hidden that submits on a click event on the front end facing form the user sees.

 

https://www.uschamber.com/co/register?entryId=45127

 

I'm scratching my head as to why only on mobile specifically iOS devices the on success doesn't fire which (this site is built on craft cms) which instead of redirecing the user to a thank you page drops them off on the homepage. Works fine on every thing else except iphone specifically.  Below is also a snippet of the code.

 

<script src="//app-ab13.marketo.com/js/forms2/js/forms2.min.js"></script>

<form id="mktoForm_2050" style="display:none"></form>
MktoForms2.loadForm("//app-ab13.marketo.com", "462-UWH-935", 2050, function(form){
    form.onSuccess(function(values, followUpUrl) {
        console.log('AZ: On Success Event');
        let $form = $('#gated-registry-form');

        let $articleUrl = $form.find('#articleUrl');

        //TODO:Make this redirect work for local dev//
        let thankYouPageUrl = '/accounts/thanks?gatedArticle=' + $articleUrl.val();

        location.href = thankYouPageUrl;

        // Return false to prevent the submission handler from taking the lead to the follow up url
        // return false;
    });

});
MktoForms2.whenReady(function(mktoForm) {
    var $mktoForm = $(mktoForm.getFormElem());
    var $form = $('#gated-registry-form');

    $form.find('#email').on('keypress', function (event) {
        if (event.keyCode == 13) {
            event.preventDefault();
        }
    });



    $('#submit-btn, #submitCompanyButton').on('click', function(e) {
        console.log('AZ: Front End Form Clicked');
        let $email = $form.find('#email');
        if ($email.length == 1) {
            $mktoForm.find('#Email').val($email.val());
        }

        let $firstName = $form.find('#firstName');
        if ($firstName.length == 1) {
            $mktoForm.find('#FirstName').val($firstName.val());
        }
        let $lastName = $form.find('#lastName');
        if ($lastName.length == 1) {
            $mktoForm.find('#LastName').val($lastName.val());
        }

        let $zipCode = $form.find('#zipCode');
        if($zipCode.length == 1){
            $mktoForm.find('#zipCode').val($zipCode.val());
        }

        let $companyName = $form.find('#companyName');

        if($companyName.length == 1){
            $mktoForm.find('#Company').val($companyName.val());
        }

        let $jobTitle = $form.find('#jobTitle');
        if ($jobTitle.length == 1) {
            $mktoForm.find('#LeadRole').val($jobTitle.text());
            $mktoForm.find('#Title').val($jobTitle.text());
        }

        let $industry = $form.find('#industry');
        if($industry.length == 1){
            $mktoForm.find('#Industry').val($industry.text());
        }

        let $partnerName = $form.find('#partnerName');
        if($partnerName.length == 1){
            $mktoForm.find('#partnerName').val($partnerName.val());
        }

        let $articleUrl = $form.find('#articleUrl');
        if($articleUrl.length == 1){
            $mktoForm.find('#articleSlug').val($articleUrl.val());
        }

        $('#mktoForm_2050 #coUserRegistered').prop('checked', true);

        $mktoForm.find('#coUserSubToCo').prop('checked', $form.find('#subscribeToCo').prop('checked'));
        $mktoForm.find('#coUserSubToMo').prop('checked', $form.find('#subscribeToMo').prop('checked'));

        const requiredCheckbox = $('.optInToCo.js-required');
        const requiredEmail = $mktoForm.find('#Email').val();
        var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;

        if ((requiredCheckbox.length && !requiredCheckbox[0].checked) && (requiredEmail.length === 0 || !re.test(String(requiredEmail).toLowerCase()))) {
            $('.response-message').text('Please enter a valid e-mail and indicate that you have read and agree to the Terms and Conditions and Privacy Policy');
            return;
        } else if (requiredCheckbox.length && !requiredCheckbox[0].checked) {
            $('.response-message').text('Please indicate that you have read and agree to the Terms and Conditions and Privacy Policy');
            return;
        } else if (requiredEmail.length === 0 || !re.test(String(requiredEmail).toLowerCase())) {
            $('.response-message').text('Please enter a valid e-mail');
            return;
        } else {
            $('.response-message').text('');
        }

        mktoForm.submit();
    });
});

Outcomes