开发者

Simple form submit with conditional redirect?

I'm building a license agreement page in which a single checkbox is used to signal "I have read the license and agree to abide by the terms, etc".

Below this is a button labeled "I Accept".

I need to hook this button to a function at the top of this php page that (1) checks to insure that the checkbox is checked and if not, prompts an alert "You must agree to the license to continue". (2) If the checkbox is checked, it redirects them to 1 of 4 links depending on the value in $_GET['productid'].

I will use a php switch statement for the redirect and I'm asking to see what options i have for the submit button to call the function without passing the submit off to another script.

<form action="?">
    <div class="accept">
        <input type="checkbox" id="accept" /><label for="accept">Yes. I Have Read and I Agree to This License Agreement and Terms of Service</label>
        <p><input type="submit" value=" I ACCEPT " /></p>
    </div>
</form>

<?php
function go(){

$id = $_GET['productid'];

    switch ($id)
    {
    case 1:
        //product 1
        header("Location: link-to-url1");
    break;
    case 2:
        //product2
        header("Location: link-to-url2");
        break;
    case 3:
        //product3
        header("Location: link-to开发者_如何学运维-url3");
        break;
    case 4:
        //product4
        header("Location: link-to-url4");
        break;

    default:
        //default
        header("Location: link-to-url-default");
    }
}
?>


<?php

$id = (int) $_GET['productid'];

switch ($id)
{
    case 1:
        //product 1
        $url = 'link-to-url1';
        break;
    case 2:
        //product2
        $url = 'link-to-url2';
        break;
    case 3:
        //product3
        $url = 'link-to-url3';
        break;
    case 4:
        //product4
        $url = 'link-to-url4';
        break;

    default:
        //default
        $url = 'link-to-url-default';
}
?>

<form action="<?php echo $url; ?>">
    <div class="accept">
        <input type="checkbox" id="accept" /><label for="accept">Yes. I Have Read and I Agree to This License Agreement and Terms of Service</label>
        <p><input type="submit" value=" I ACCEPT " /></p>
    </div>
</form>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜