35

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

页面上有很多复选框,但我不知道如何在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>
4

4 回答 4

55

有许多链接可以让您知道如何处理 php.ini 中复选框的帖子值。看看这个链接:http ://www.html-form-guide.com/php-form/php-form-checkbox.html

单个复选框

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代码:

<?php

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

?>

复选框组

<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] . " ");
    }
  }
?>
于 2013-02-08T21:05:32.030 回答
10

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

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

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

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

这将返回

<p>off</p>

或者

<p>on</p>
于 2015-12-01T21:14:24.270 回答
4

你应该使用

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

在你的form.

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

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

它将您的表格发布到您选择的行动中。

从 php 你可以得到这个值

$_POST['booking-check'];
于 2013-02-08T21:04:39.770 回答
1

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

name="booking.php"

利用

action="booking.php"

然后,在 booking.php 中使用

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

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

<input type='submit'>
于 2013-02-08T21:05:55.463 回答