Shadowbox 内部的表单验证方法有哪些?

发布于 2024-09-19 06:57:36 字数 251 浏览 7 评论 0原文

好吧,我在影子盒子里有一个表格,这个东西不会验证......我已经尝试过一百万种不同的方式。它也存在于 WordPress 主题中,我认为这不会破坏它。 Jquery 被加载到标头中。

该表格已粘贴到要点中: http://gist.github.com/578270

有什么想法吗?非常感谢,感觉我的头撞到墙上了。

Ok I have a form inside a shadowbox, this thing will just not validate... I have tried it a million different ways. It also lives inside a Wordpress Theme which I don't think is breaking it. Jquery is loaded in the header.

the form is pasted into a gist: http://gist.github.com/578270

Any ideas? Thanks so much, feel like I am banging my head into a wall.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2024-09-26 06:58:08

诀窍是使用 onFinish 回调函数来触发 Shadowbox 内表单的验证。如果您像我一样为表单使用 ID,shadowbox 实际上会创建表单的重复副本,因此您需要在 Shadowbox 本身内定位表单。我使用 #sb-player 来做到这一点。

HTML Shadowbox 链接

<a href="#newsletter-signup-wrapper" class="newsletter-signup UniversLTStd-Cn">Newsletter Sign-up</a>

JavaScript/jQuery

$('a.newsletter-signup').click(function(){
    Shadowbox.open({
        width: 562,
        height: 395,
        player: 'inline',
        content: this.href,
        options: {
            onFinish: function(){
                $('#sb-player #newsletter-signup-form').validate();
            }
        }
    });
    return false;
});

HTML 表单(隐藏在页脚中)

<div id="newsletter-signup-wrapper">
    <div id="newsletter-signup">
        <form action="" id="newsletter-signup-form" target="_parent" method="POST">
            <div class="gform_body">
                <ul class="gform_fields">
                    <li class="gfield">
                        <label class="gfield_label" for="first_name">First Name <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="first_name" maxlength="40" name="first_name" size="20" type="text" />
                        </div>
                    </li>
                    <li class="gfield">
                        <label class="gfield_label" for="last_name">Last Name <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="last_name" maxlength="80" name="last_name" size="20" type="text" />
                        </div>
                    </li>
                    <li class="gfield">
                        <label class="gfield_label" for="email">Email <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="email" maxlength="80" name="email" size="20" type="text" />
                        </div>
                    </li>
                    <li class="gfield">
                        <label class="gfield_label" for="company">Company <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="company" maxlength="40" name="company" size="20" type="text" />
                        </div>
                    </li>
                </ul>
            </div>
            <div class="gform_footer">
                <input class="button" type="submit" name="submit" value="Sign-up!">
            </div>
        </form>
    </div>
</div><!--// end #newsletter-signup-wrapper -->

我希望这有帮助,我很高兴如果需要的话可以更详细地解释。

The trick is to use the onFinish callback function to trigger the validation for the form that is inside the Shadowbox. If you use an ID for your form like I did, shadowbox will actually create a duplicate copy of the form so you need to target the form within the shadowbox itself. I used #sb-player to do this.

HTML Shadowbox Link

<a href="#newsletter-signup-wrapper" class="newsletter-signup UniversLTStd-Cn">Newsletter Sign-up</a>

JavaScript/jQuery

$('a.newsletter-signup').click(function(){
    Shadowbox.open({
        width: 562,
        height: 395,
        player: 'inline',
        content: this.href,
        options: {
            onFinish: function(){
                $('#sb-player #newsletter-signup-form').validate();
            }
        }
    });
    return false;
});

HTML Form (hidden in footer)

<div id="newsletter-signup-wrapper">
    <div id="newsletter-signup">
        <form action="" id="newsletter-signup-form" target="_parent" method="POST">
            <div class="gform_body">
                <ul class="gform_fields">
                    <li class="gfield">
                        <label class="gfield_label" for="first_name">First Name <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="first_name" maxlength="40" name="first_name" size="20" type="text" />
                        </div>
                    </li>
                    <li class="gfield">
                        <label class="gfield_label" for="last_name">Last Name <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="last_name" maxlength="80" name="last_name" size="20" type="text" />
                        </div>
                    </li>
                    <li class="gfield">
                        <label class="gfield_label" for="email">Email <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="email" maxlength="80" name="email" size="20" type="text" />
                        </div>
                    </li>
                    <li class="gfield">
                        <label class="gfield_label" for="company">Company <span class="gfield_required">*</span></label>
                        <div class="ginput_container">
                            <input class="medium required" id="company" maxlength="40" name="company" size="20" type="text" />
                        </div>
                    </li>
                </ul>
            </div>
            <div class="gform_footer">
                <input class="button" type="submit" name="submit" value="Sign-up!">
            </div>
        </form>
    </div>
</div><!--// end #newsletter-signup-wrapper -->

I hope this helps, I'm happy to explain in more detail if needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文