#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Posts
    1
    Rep Power
    0

    How to get value of out checkbox.


    Code:
    <form action="http://example.com" method="GET">
        <input type="checkbox" name="reason" value="one">
        <input type="checkbox" name="reason" value="two">
        <input type="submit" value="Submit">
    </form>
    So this works and redirects me to:
    Code:
    http://example.com/?reason=one&reason=two
    Which is as expected. But how do I parse it?

    If I ask for:
    PHP Code:
    <?php echo $_GET["reason"]; ?>
    I only get "two" as response. How do I parse both checkboxes at the same time without JavaScript?
    How could I receive "one" and "two" with this query?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jul 2003
    Posts
    4,350
    Rep Power
    630
    You need to use different names for the checkboxes or use an array if they are related.
    Code:
    <input type="checkbox" name="reason[]" value="one">
    <input type="checkbox" name="reason[]" value="two">
    $_GET will then return an array over which you can loop. You also should use 'count' to determine if any boxes were checked.

    Comments on this post

    • zetjkiqp agrees
    Last edited by gw1500se; December 7th, 2016 at 09:34 AM.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.

IMN logo majestic logo threadwatch logo seochat tools logo