在完成表单操作后重定向 [英] Redirecting after completion of form action

查看:130
本文介绍了在完成表单操作后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码进行表单操作,

  //包含




require_once('inc / mysql_wrapper.php');
$ DB = get_db_connection();
require_once('inc / defines.inc.php');
require_once('lib / functions.php');
require_once('lib / framework.php');
require_once('lib / specific.php');
require_once('lib / table_editor.php');
require_once('lib / user.php');
require_once('models / basic.php');
require_once('models / list.php');
require_once('swiftmailer / lib / swift_required.php');
require_once('recaptcha / recaptchalib.php');
// end包含

$ q =SELECT value FROM $ T_SETTINGS
WHERE name ='register';
$ register = $ DB-> oq($ q);

$ optin = get_setting(optin);

//选择自定义字段(如果有)
$ q =SELECT * FROM $ T_FIELDS
WHERE list_id ='$ _ GET [list_id]'
ORDER BY id ;
$ efields = $ DB-> aq($ q);

//选择邮件列表
$ q =SELECT * FROM $ T_LISTS WHERE id ='$ _ GET [list_id]';
$ list = $ DB-> sq($ q);

if(!empty($ _ POST ['ok']))
{
//如果需要,验证recaptcha
if($ list ['require_recaptcha'] )
{
$ resp = recaptcha_check_answer(RECAPTCHA_PRIVATE,
$ _SERVER [REMOTE_ADDR],
$ _POST [recaptcha_challenge_field],
$ _POST [recaptcha_response_field ]);

if(!$ resp-> is_valid)
{
$ recaptcha_error =看起来你输入的单词不正确!
$ template =templates / register.html;
require_once('templates / master.html');
出口;
}
}

User :: register($ _ POST,$ efields,$ optin);

if(!empty($ list ['redirect_to']))
{
redirect($ list ['redirect_to']);
出口;
}

$ template =templates / message.html;
}
else
{
$ template =templates / register.html;
}

require_once('templates / master.html');

排除其他一些选项,主要是这个表单接收的表单数据是


姓名,电子邮件,确定(检查提交表单是否已提交的标志)

在表单提交后,如何将此页面重定向到thanks.php?

解决方案

谢谢.php应该控制数据格式和显示消息,或者重定向(通过放置在标题中的字符串:<$ c $因此,如果数据是正确的(并且如果需要控件,但是需要一个控件,但是我想是的)你不需要重定向。



更重要的是,如果controll在原始页面(简单的JS或JQuery?)中完成,您可以保存一些重定向。
这样会更有效率!


i am using the following code for form action,

// includes




require_once('inc/mysql_wrapper.php');
$DB=get_db_connection(); 
require_once('inc/defines.inc.php');
require_once('lib/functions.php');
require_once('lib/framework.php');
require_once('lib/specific.php');
require_once('lib/table_editor.php');
require_once('lib/user.php');
require_once('models/basic.php');
require_once('models/list.php');
require_once('swiftmailer/lib/swift_required.php');
require_once('recaptcha/recaptchalib.php');
// end includes

$q="SELECT value FROM $T_SETTINGS
WHERE name='register'";
$register=$DB->oq($q);

$optin=get_setting("optin");

// select custom fields if any
$q="SELECT * FROM $T_FIELDS 
WHERE list_id='$_GET[list_id]'
ORDER BY id";
$efields=$DB->aq($q);

// select mailing list
$q="SELECT * FROM $T_LISTS WHERE id='$_GET[list_id]'";
$list=$DB->sq($q);

if(!empty($_POST['ok']))
{
    // validate recaptcha if required
    if($list['require_recaptcha'])
    {
        $resp = recaptcha_check_answer (RECAPTCHA_PRIVATE,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

        if (!$resp->is_valid) 
        {
            $recaptcha_error="Looks like the words you entered are not correct!";        
            $template="templates/register.html";
            require_once('templates/master.html');
            exit;
        }                        
    }

    User::register($_POST, $efields, $optin);

    if(!empty($list['redirect_to']))
    {
        redirect($list['redirect_to']);
        exit;
    }

    $template="templates/message.html";
}
else
{
    $template="templates/register.html";
}

require_once('templates/master.html');

excluding some other options, majorly the form data which this form recieves is

name , email , ok (a flag to check that the the orginating form was submitted)

how can I redirect this page to thanks.php when the form has been submitted?

解决方案

Can't you post it directly in thanks.php?

Thanks.php should control data format and display message, or redirect (by place into header that string: header('Location: urlOfForm-postedPage);.

So, if data are correct (and if a control is needed, but I suppose yes) you don't need a redirect.

More over, if controll are done into the original page (simply JS or JQuery?), you can save some redirects. And that will be more efficient!

这篇关于在完成表单操作后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆