开发者

What are methods of form validation from inside a shadowbox?

开发者 https://www.devze.com 2023-01-15 20:31 出处:网络
Ok I have a form inside a shadowbox, this thing will just not validate... I have tried it a mill开发者_JAVA百科ion different ways.It also lives inside a Wordpress Theme which I don\'t think is breakin

Ok I have a form inside a shadowbox, this thing will just not validate... I have tried it a mill开发者_JAVA百科ion 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消