1

我正在尝试制作一个可重用的 js 组件,它使用通过他们的 js api 嵌入到页面中的 marketo 表单。我正在填写表格并将其放入引导模式,并使用链接切换模式。

这是html

<div class="modal-form" 
                data-form-id="1619" data-success-url="https://google.com/" data-redirect="true" 
                data-form-result="blank" data-sucess-msg="false">
                <a type="button" class="cta-button secondary-button" data-toggle="modal" data-target="#mktoForm_456-modal" >
                    New Tab Redirect Form
                </a>
                <div class="modal fade" id="mktoForm_456-modal" tabindex="-1" role="dialog">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <div class="logo"></div>
                                <h4>Test Form Title</h4>
                                <button type="button" class="close x-button" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&nbsp;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                <div class="modal-form-content" id="modal-mktoForm_1619-intro">
                                    <h2>Secondary  Redirect in new tab</h2>
                                </div>
                                <form id="mktoForm_1619"></form>
                                <div class="modal-form-content" id="modal-mktoForm_1619-chaser">
                                    <p>Bye Bye.</p>
                                </div>
                            </div>
                        </div><!-- /.modal-content -->
                        <div class="modal-sucess-msg" id="modal-success-1619"></div>
                    </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
            </div>

这里是js

$('.modal-form').each(function () {
        var formModal = $(this);
        var formID = $(this).attr('data-form-id') || 1619;
        var componentID = $(this).attr('data-componentID') || '';
        var formRedir = $(this).attr('data-redirect') || false;
        var formResult = $(this).attr('data-form-result') || "blank";
        var formSucessUrl = $(this).attr('data-success-url') || '';
        var formSuccessMsg = $(this).attr('data-sucess-msg') || false;
        MktoForms2.loadForm("//app-ab13.marketo.com", "754-FXO-315", formID, function (form){ 
            form.onSuccess(function(values, followUpUrl){
                formModal.find(".modal-content").fadeOut('fast');
                if (formRedir == "true") {
                    if (formResult == "blank") {
                        window.open(formSucessUrl, '_blank');
                        formModal.find(".modal.fade").modal('hide');
                    } else {
                        location.href = formSucessUrl;
                    }
                } else if (formRedir =="false" && formSuccessMsg =="true") {
                    formModal.find(".modal-sucess-msg").fadeIn(100).delay(5000).fadeOut('slow').delay(600, function(){
                        formModal.find(".modal.fade").modal('hide');
                        formModal.on('hidden.bs.modal', function () {
                            formModal.find(".modal-content").show();
                            formModal.find(".modal-sucess-msg").hide();
                        });
                    }); 
                }

                return false;
            });
        });
    });

要求之一是使用相同的表单(联系表单)并将其配置为定义不同的成功 url。所以有多个链接、带表单的模式和重定向 url。

那么除了他们的 mktoForm_<> 之外,有没有办法定义一个替代的表单标签 ID?

4

0 回答 0