post checkbox value

前端 未结 4 1121
无人共我
无人共我 2020-12-08 04:19

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

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

相关标签:
4条回答
  • 2020-12-08 04:59

    You should use

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

    inside your form.

    and add action into your form tag for example:

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

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

    From php you can get this value by

    $_POST['booking-check'];
    
    0 讨论(0)
  • 2020-12-08 05:06

    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>
    
    0 讨论(0)
  • 2020-12-08 05:17

    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

    Single check box

    HTML code:

    <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
    
    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] . " ");
        }
      }
    ?>
    
    0 讨论(0)
  • 2020-12-08 05:19

    In your form tag, rather than

    name="booking.php"
    

    use

    action="booking.php"
    

    And then, in booking.php use

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

    Also, you'll need a submit button in there

    <input type='submit'>
    
    0 讨论(0)
提交回复
热议问题