Redirecting after completion of form action

2019-09-08 06:46发布

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?

4条回答
爷的心禁止访问
2楼-- · 2019-09-08 07:33

If everything goes well you can use php header to get to the desired page:

header( 'Location: thanks.php' );
查看更多
女痞
3楼-- · 2019-09-08 07:34

When the data is valid, add:

header('Location: http://www.example.com/thanks.php');
查看更多
The star\"
4楼-- · 2019-09-08 07:42

or javascript:

?>

<script type="text/javascript">
window.location = "your>"
</script>

<?php
查看更多
迷人小祖宗
5楼-- · 2019-09-08 07:47

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!

查看更多
登录 后发表回答