2011-03-03 3 views
0

나는 하나의 확인란을 사용하여 "라이센스를 읽었으며 약관을 준수 할 것에 동의합니다"라는 라이센스 계약 페이지를 구축하고 있습니다.조건부 리디렉션으로 간단한 양식을 제출 하시겠습니까?

아래에는 "동의합니다"라는 버튼이 있습니다.

이 PHP 페이지 상단의 기능에이 버튼을 연결해야합니다. (1) 확인란이 선택되어 있는지 확인하고 그렇지 않으면 "계속하려면 라이센스에 동의해야합니다."라는 경고를 표시합니다. (2) 체크 박스를 체크하면 $ _GET [ 'productid']의 값에 따라 4 개의 링크 중 1 개로 리디렉션됩니다.

나는 리다이렉트를 위해 php switch 문을 사용할 것이고, 나는 submit 버튼을 다른 스크립트로 넘기지 않고 함수를 호출 할 수있는 옵션을 보길 원한다.

<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"); 
    } 
} 
?> 
+0

당신은 자바 스크립트를 통해 양식 동작을 변경하거나 – random

답변

0
<?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

이 조금을 최적화 할 수있을 수 있습니다 쳤을 때 당신은 컬을 통해 다른 페이지로 데이터를 보낼 수 있습니까? –

+0

링크가 양식 제출에서 오는 사실은 페이팔 게이트웨이를 버리고 있다고 생각합니다. 나는 위치 리디렉션을해야하고 양식을 제출하지 않아야한다고 믿습니다. 예를 들어 페이팔 로그인 화면이 표시되고 브라우저의 주소 표시 줄에 링크를 직접 붙여 넣으면 정상적인 판매 페이지가 표시되지 않습니다. –

관련 문제