【问题标题】:getting a value from a form and printing the checked values only从表单中获取值并仅打印检查的值
【发布时间】:2015-01-20 00:52:00
【问题描述】:

我需要获取用户选中的复选框值并打印出来。

我目前正在做的事情如下,但我不确定要在表单中编写什么动作脚本

<form id="shop" method="POST" action="">
  <section id="latest" class="last clear">
    <article class="one_quarter">
      <figure><img src="images/g1.jpg" width="215" height="100" alt="">
        <figcaption>
          Value : $100 <br />
          Price : $75.00
          <input type="checkbox" name="one" />
          <br />
          <footer class="more"><a href="#">Read More &raquo;</a></footer>
        </figcaption>
      </figure>
    </article>
    <article class="one_quarter">
      <figure><img src="images/g2.jpg" width="215" height="100" alt="">
        <figcaption>
           Value : $100 <br />
          Price : $82.00
          <input type="checkbox" name="two" />
          <br />
          <footer class="more"><a href="#">Read More &raquo;</a></footer>
        </figcaption>
      </figure>
    </article>

【问题讨论】:

    标签: php html forms web


    【解决方案1】:

    在同一目录中创建一个类似“result.php”的文件

    对“result.php”进行操作

    结果.php:

    if(isset($_POST["one"])){
        echo $_POST["one"];
    }
     if(isset($_POST["two"])){
        echo $_POST["two"];
    }
    

    【讨论】:

    • 您建议的方式将让用户一次仅使用单选按钮选择一个答案,其次此代码 echo $_POST["one"];回声 $_POST["two"];将只打印两者的值!我只需要选中的值
    • 好的,现在知道了,编辑了代码,现在如果两者都被选中,它会打印两个,如果 1 被选中,则打印 1,如果都没有被选中则什么都没有
    • 它有效,但它说!而不是给出该字段的名称或我给它的某种名称!它只是说!
    • 尝试为您的输入添加一个名称,例如:
    猜你喜欢
    • 1970-01-01
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 2013-04-06
    • 2021-06-20
    • 1970-01-01
    • 2014-01-01
    • 1970-01-01
    相关资源
    最近更新 更多