根据从弹出窗口中选择的复选框,重定向


As per checkbox selected from a popup window, redirection

我有一个页面的按钮,打开一个弹出窗口。这个弹出窗口有两个复选框。如果选中复选框1,它应该重定向到page1.php,如果选中复选框2,它应该重定向到page2.php,如果两个复选框都选中,它应该重定向到page3.php。我已经在javascript和php中实现了这个脚本。

弹出窗口脚本如下:

 <html>
 <head>
<script language="Javascript">
    function redirectTo(){
        window.opener.location.href="grabvalues.php";
        self.close();
    }
</script>
<style>
 #checkboxes,
    #submit-button{
    display:none;
    }
</style>
 <script language="JavaScript">
 function rework(){
   document.getElementById("checkboxes").style.display = "block"
   document.getElementById("submit-button").style.display = "block"
   document.getElementById("rework-button").style.display = "none"
 }
 </script>

 </head>
 <body>

 <form method="POST">
    <input type="button" id="rework-button" value="Rework" onclick="rework()"/>
 <div id="checkboxes">
  Tech & Price: <input type="checkbox" id="techprice" name="techprice" value="techprice" />
  Terms & Conditions: <input type="checkbox" id="terms" name="terms" value="terms" />
 </div>

 <input type="submit" id="submit-button" value="Proceed" OnClick="redirectTo()"/>

 </form>
 </body>
 </html>

grabvalues.php脚本如下。这个PHP脚本

有问题
 <?php
    $techprice = $_POST['techprice'];
    $terms = $_POST['terms'];
    if ($techprice=1) {
   Redirect('page1.php', true);
    } 
     if ($terms=1) {
        Redirect('page2.php', true);
    } 
    if ($techprice=1 && $terms=1) {
    Redirect('page3.php', true);
    }
 ?>

首先需要将值提交给PHP

window.opener.location.href = "grabvalues.php?techprice=" + (techprice.checked ? 1 : 0) + '&terms=' + (terms.checked ? 1 : 0);

那么你的PHP代码应该改成

 <?php
    $techprice = $_GET['techprice'];
    $terms = $_GET['terms'];
    if ($techprice=1 && $terms=1) {
        Redirect('page3.php', true);
    } elseif ($techprice=1) {
        Redirect('page1.php', true);
    } elseif ($terms=1) {
        Redirect('page2.php', true);
    } 

 ?>

使用

 $techprice = $_POST['techprice'];
    $terms = $_POST['terms'];
    if ($techprice ==1 && $terms==1) {
    Redirect('page3.php', true);
    }
    elseif ($techprice==1) {
        Redirect('page1.php', true);
    } 
    elseif ($terms==1) {
        Redirect('page2.php', true);
    }
    else
    {
        // do nothing
    }