【问题标题】:Checkboxes don't send to right url复选框不会发送到正确的网址
【发布时间】:2017-04-18 03:39:14
【问题描述】:

当我查看此表单时,我总是选择 google 选项,无论是哪种组合。我不知道我做错了什么。我在其他情况下对复选框使用相同的表单。 1-6 总是谷歌。连不配置的多选都是google的。

.pic{
        background: url("#") no-repeat;
        width:616px;
        height:525px;
        position: relative;
        }
    input[type="checkbox"] {
          transform:scale(1.3, 1.3);
        }
        .poin1{
        left: 548px;
        bottom:59px;
        position: absolute;
        }
        .poin2{
        left: 540px;
        bottom:155px;
        position: absolute;
        }
        .poin3{
        left: 500px;
        bottom:265px;
        position: absolute;
        }
        .poin4{
        left: 495px;
        bottom:325px;
        position: absolute;
        }
      .poin5{
        left: 479px;
        bottom:385px;
        position: absolute;
        }
      .poin6{
        left: 465px;
        bottom:460px;
        position: absolute;
        }



<form method="post" action="../includes/messung_jeans.php">  <div class="pic">
    <input type="checkbox" id="cb1" name="cb1" value="m1" class="poin1">
    <input type="checkbox" id="cb2" name="cb2" value="m2" class="poin2">
    <input type="checkbox" id="cb3" name="cb3" value="m3" class="poin3">
    <input type="checkbox" id="cb4" name="cb4" value="m4" class="poin4">
   <input type="checkbox" id="cb5" name="cb5" value="m5" class="poin5">
   <input type="checkbox" id="cb6" name="cb6" value="m6" class="poin6">


</div>
  <div class="buttonHolder">
<input type="submit" name="send" <a class="btn primary-button" value="Weiter" /> </a>

    </div>



<?

if($_POST['cb1'] == m1){
    header("Location: http://www.google.com");
}
elseif($_POST['cb2'] == m2 ){
    header("Location: http://www.yahoo.com");
}
elseif($_POST['cb2'] == m2 && $_POST['cb1'] == m1 ){
    header("Location: http://www.bild.de");
}
elseif($_POST['cb3'] == m3 ){
    header("Location: http://www.bing.com");
}
elseif($_POST['cb4'] == m4 ){
    header("Location: http://www.bing.com");
}
elseif($_POST['cb5'] == m5 ){
    header("Location: http://www.bing.com");
}
elseif($_POST['cb6'] ==  m6 ){
    header("Location: http://www.bing.com");
}

else {
    header("Location: http://www.floridataxreduction.com");
}  
?>

【问题讨论】:

  • 我认为我们不需要你的 CSS。这有点让人分心xD

标签: php html css forms checkbox


【解决方案1】:

<form method="post" action="../includes/messung_jeans.php">  <div class="pic">
    <input type="checkbox" id="cb1" name="cb1" value="m1" class="poin1">
    <input type="checkbox" id="cb2" name="cb2" value="m2" class="poin2">
    <input type="checkbox" id="cb3" name="cb3" value="m3" class="poin3">
    <input type="checkbox" id="cb4" name="cb4" value="m4" class="poin4">
   <input type="checkbox" id="cb5" name="cb5" value="m5" class="poin5">
   <input type="checkbox" id="cb6" name="cb6" value="m6" class="poin6">


</div>
  <div class="buttonHolder">
<input type="submit" name="send" class="btn primary-button" value="Weiter" /> 

    </div>

如下添加您的 PHP 代码。

<?php
if(isset($_POST['cb1']) && !isset($_POST['cb2'])){
   header("Location: http://www.google.com");
}
elseif(isset($_POST['cb2']) && !isset($_POST['cb1'])){
   header("Location: http://www.yahoo.com");
}
elseif(isset($_POST['cb2']) && isset($_POST['cb1'])){
   header("Location: http://www.bild.de");
}
elseif(isset($_POST['cb3'])){
header("Location: http://www.bing.com");
}
elseif(isset($_POST['cb4'])){
header("Location: http://www.bing.com");
}
elseif(isset($_POST['cb5'])){
   header("Location: http://www.bing.com");
}
elseif(isset($_POST['cb6'])){
   header("Location: http://www.bing.com");
}
else {
   header("Location: http://www.floridataxreduction.com");
}
?>

【讨论】:

  • 谢谢,这成功了!但是: elseif(isset($_POST['cb2']) && isset($_POST['cb1'])){ header("Location: bild.de"); } ----如果我试试这个,它又是谷歌
  • 你能解释一下为什么上面的海报使用 exit() 以及你为什么使用这个结构。什么更好?
  • 在上面的海报中不需要使用 exists()。因为如果条件为真,它会重定向到标题位置,而不是检查另一个条件......
  • 啊我明白了,说明他的出口没用了,如果我以后需要1,2和3,因为它会停在1和2
  • @fillat 是的,它需要在那里格式化数据和会话,并阻止对脚本其余部分的任何恶意请求。在你说什么之前,在改变主意之前,最好的答案是什么,不要听初学者的意见,最好去php网站,从专家那里了解更多关于header()和exit()的信息。 http://php.net/manual/en/function.header.phphttp://stackoverflow.com/questions/2747791/why-i-have-to-call-exit-after-redirection-through-headerlocation-in-phphttp://stackoverflow.com/questions/8665985/php-utilizing-exit-or-die-after-headerlocation
猜你喜欢
  • 1970-01-01
  • 2016-10-31
  • 1970-01-01
  • 2021-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多