使用colorbox在相同的colorbox中处理用户注册和响应


Using colorbox to process user registration and response in same colorbox

我的冒险还在继续。。。在我的页面上,我想用colorbox显示一个注册表格,允许用户提交由php脚本处理的表格,然后在colorbox中显示一条感谢风格的消息,用户将关闭该消息。

目前,我的处理脚本与表单位于同一页面中,这在颜色框之外是独立的。

我在这里看到了类似的问题,建议使用ajax调用发布表单

$('form').live('submit', function(e){
var successHref = this.action,
    errorHref = "formError.php";
e.preventDefault();
$('#cboxLoadingGraphic').fadeIn();
$.ajax({
    type: "POST",
    url: "processForm.php",
    data: {someData: $("#someData").val()},
    success: function(response) {
        if(response=="ok") {
            console.log("response: "+response);
            $.colorbox({
                open:true,
                href: successHref   
            });
        } else {
            $.colorbox({
                open:true,
                href: errorHref
            });
        }
    },
    dataType: "html"
});
return false;
});

我对此有点困惑。。。。

我想我可以通过$,ajax发送我的表单(尽管我很清楚),但我不清楚如何处理表单的响应。我需要我的php脚本输出什么(以及如何)才能显示感谢消息?它只是php脚本中的echo语句吗?

我应该把我的处理脚本从表单中分离出来吗?)我这样做是因为我不断出现路径错误,而且当时更容易。

感谢

成功!

我已经设法让它发挥作用了——最终一切都合乎逻辑——遗憾的是,我不是很合乎逻辑。。

第一步是将php表单流程脚本分离到一个单独的文件中。

Colorbox链接到表单所有工作正常

在php脚本中使用ajax post,并等待php脚本返回的消息。

php脚本根据成功或失败生成两条html消息,然后通过替换div 中的表单html来显示在颜色框中

耶!