php 发布复选框值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14781270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:57:34  来源:igfitidea点击:

post checkbox value

phpcheckbox

提问by user2055788

I want to post values of check boxes on booking.php page.

我想在booking.php 页面上发布复选框的值。

There are many checkboxes on the page but I don't know how to post on booking.phppage.

页面上有很多复选框,但我不知道如何在booking.php页面上发布。

<form name="booking.php" method="post">
    <label for="tour" class="tour-label">Add to Tour List</label>
    <input type="checkbox" name="booking-check" value="Desert Safari" />
</form>
<div class="details"><a href="booking.php">Book Selected Tours</a></div>

回答by C.O.D.E

There are many links that lets you know how to handle post values from checkboxes in php. Look at this link: http://www.html-form-guide.com/php-form/php-form-checkbox.html

有许多链接可让您了解如何处理 php 中复选框中的 post 值。看看这个链接:http: //www.html-form-guide.com/php-form/php-form-checkbox.html

Single check box

单个复选框

HTML code:

HTML代码:

<form action="checkbox-form.php" method="post">
    Do you need wheelchair access?
    <input type="checkbox" name="formWheelchair" value="Yes" />
    <input type="submit" name="formSubmit" value="Submit" />
</form>

PHP Code:

PHP代码:

<?php

if (isset($_POST['formWheelchair']) && $_POST['formWheelchair'] == 'Yes') 
{
    echo "Need wheelchair access.";
}
else
{
    echo "Do not Need wheelchair access.";
}    

?>

Check box group

复选框组

<form action="checkbox-form.php" method="post">
    Which buildings do you want access to?<br />
    <input type="checkbox" name="formDoor[]" value="A" />Acorn Building<br />
    <input type="checkbox" name="formDoor[]" value="B" />Brown Hall<br />
    <input type="checkbox" name="formDoor[]" value="C" />Carnegie Complex<br />
    <input type="checkbox" name="formDoor[]" value="D" />Drake Commons<br />
    <input type="checkbox" name="formDoor[]" value="E" />Elliot House

    <input type="submit" name="formSubmit" value="Submit" />
 /form>

<?php
  $aDoor = $_POST['formDoor'];
  if(empty($aDoor)) 
  {
    echo("You didn't select any buildings.");
  } 
  else
  {
    $N = count($aDoor);

    echo("You selected $N door(s): ");
    for($i=0; $i < $N; $i++)
    {
      echo($aDoor[$i] . " ");
    }
  }
?>

回答by bonjour

in normal time, checkboxes return an on/off value.

在正常情况下,复选框返回一个开/关值。

you can verify it with this code:

您可以使用以下代码进行验证:

<form action method="POST">
      <input type="checkbox" name="hello"/>
</form>

<?php
if(isset($_POST['hello'])) echo('<p>'.$_POST['hello'].'</p>');
?>

this will return

这将返回

<p>off</p>

or

或者

<p>on</p>

回答by Mateusz Rogulski

You should use

你应该使用

<input type="submit" value="submit" />

inside your form.

在您的form.

and add actioninto your formtag for example:

并添加action到您的form标签中,例如:

<form action="booking.php" method="post">

It's post your form into action which you choose.

它是将您的表单发布到您选择的操作中。

From php you can get this value by

从 php 你可以得到这个值

$_POST['booking-check'];

回答by Martin Sheeks

In your form tag, rather than

在您的表单标签中,而不是

name="booking.php"

use

action="booking.php"

And then, in booking.php use

然后,在booking.php中使用

$checkValue = $_POST['booking-check'];

Also, you'll need a submit button in there

此外,您还需要一个提交按钮

<input type='submit'>