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 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)