处理表单操作以使用facebox打开它

时间:2012-09-06 05:31:06

标签: php jquery html css facebox

我正在使用facebox来显示联系表单,但是当用户选择提交时,我想要动作,对于这个例子,我将调用action =“contact_send.php”也在facebox中打开。目前,通过将rel属性声明为facebox,可以轻松打开指向facebox的链接 e.g。

<a href="contact.html" rel="facebox">Contact</a>

这会在facebox窗口中打开contact.html,但我希望此表单的操作也可以在灯箱中打开,是否有人有任何可能有帮助的建议?

提前谢谢 -Ashutosh

1 个答案:

答案 0 :(得分:0)

您的HTML表单

<form id="contactfrm" method="post" onsubmit="return false;">
 ....your form elements
 <input type="submit" onclick="submitContact();" />
</form>

编辑:

您的脚本

现在使用jquery提交表单

<script type="text/javascript">
function submitContact() {

    $.facebox(function() {

        $.ajax({
            data: { 'name' : $('#name').val(), 'message' : $('#message').val() },  //Make sure to change these values that reflects yours.
            error: function() {
                $.facebox('There was error sending your message.');
            },
            success: function(data) {
                $.facebox(data); // the data returned by contact_send.php
            },
            type: 'post',
            url: 'contact_send.php'
        });

    });

}
</script>

当您单击页面上的“提交”按钮时,此代码将打开facebox并处理您发送到contact_send.php页面的变量,并将该页面的输出返回到facebox。