duanpuchun5275 2014-08-04 09:46
浏览 91
已采纳

未选中的复选框,用于在php中执行操作

i wanted to know how to detect for and unchecked check box and make it perform and action.Basically if the checkbox is unchecked it should load another page. This doesnt seem to be working , any help?

<?php
if(!isset($_POST['checkbox1'])) 
{
    $swag=fopen("empty.php","r");
}
?>

The HTML bit:

<html>
<title>Zeromilez | Shop</title>
<!--The following script tag downloads a font from the Adobe Edge Web Fonts server for use within the web page. We recommend that you do not modify it.--><script>var __adobewebfontsappname__="dreamweaver"</script><script src="http://use.edgefonts.net/source-sans-pro:n2,n4:default;atomic-age:n4:default.js" type="text/javascript"></script>

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<div id="header-wrapper">
    <div id="header" class="container">
        <div id="logo">
            <h1><a href='#'>Zeromilez.com</a></h1>
        </div>
        <div id="menu">
            <ul>
                <li ><a href="index.php" accesskey="1" title=""><i class="fa fa-home fa-fw fa-2x"></i> Home</a></li>

                <li class="current_page_item"><a href="#" title="" class="active" accesskey="4"><i class="fa fa-shopping-cart fa-2x"></i>     shop</a></li>
                <li><a href="feedback.php" accesskey="5" title=""><i class="fa fa-envelope fa-2x"></i> Feedback</a></li>

            </ul>
        </div>
    </div>
    <div id="banner" class="container"></div>
</div>
<div class="wrapper">
  <form id="form1" name="form1" method="POST">
    <div id="three-column" class="container">
      <div id="tbox1">
        <div class="title">
          <p>
            <input name="name" type="text" id="textfield" style="background-color:#4D4D4D;margin:0;color:#FFF; text-align:center;" value="Fox's berries-500gms" disabled>
          </p>
          <h2><img src="fox.jpg" height="90" width="100"></h2>
        </div>
        <p>
          <input name="cost" type="text" id="textfield2" value="Rs 100" style="background-color:#4D4D4D;color:#fff; text-align:center; padding:0; margin:0;" disabled>
        </p>
        <p>
          <input type="checkbox" name="checkbox1" id="checkbox1">
          Add to cart
          <label for="checkbox1"></label>
        </p>
      </div>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>&nbsp;</p>
      <p>
        <input type="submit" name="submit" id="submit" value="Submit">
      </p>
      <p>&nbsp;</p>
    </div>
    <input type="hidden" name="MM_insert" value="form1">
  </form>
</div>
<div id="copyright" class="container">
  <p>&#169; Zeromilez.com 2014 | All rights reserved | Made with &#10084; in Bangalore, India  
  </p><p>Follow us:<br/><img src="facebook.png" width="30" height="30" alt=""/><img src="twitter.png" width="30" height="30" alt=""/><img src="google.png" width="30" height="30" alt=""/><img src="yahoo.png" width="30" height="30" alt=""/><img src="pinterest.png" width="30" height="30" alt=""/></p><div id ="about_me" >
  <p>About Me:<br/><img src="about_me.png" width="100" height="100" alt=""><br/>Hi, I am Mohit Bhasi, a 16 year old aspiring web developer. Hope you all enjoy my first website :)</p></div>
</h4></div>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • duanhuang7591 2014-08-04 09:59
    关注

    When receiving the POST parameters in the php side, if the parameter relative to the checkbox comes in, that's because the checkbox is selected. If the parameter doesn't come in the POST parameters it's unchecked.

    You can do something like this:

    if(isset($_POST['checkbox_parameter']){
        echo "Checkbox is selected!";
    }
    else {
        echo "Checkbox not selected.";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?