Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Form not processing check boxes.

    I have created a simple html+ php form for processing the checkboxes.
    If the checkbox is clicked , then i get the desired message or i get error

    Notice: Undefined index: checkbox1 in C:\wamp\www\db\output.php on line 2
    User denied clicking the frog.
    The html code is

    <html>
    </body>

    <form method=post action="output.php">
    <label><input type="checkbox" name="checkbox1" value="helpivebeenclicked">Please click me, I look like a frog, but I'm a princess!</label>
    <br>
    <label><input type="checkbox" name="checkbox2" value="noclicked">I am not going to click on it </label>
    <br>
    <input type=submit>
    </form>

    </body>
    </html>



    the php code is :

    PHP Code:
    <?php
    $checkbox1
    =$_REQUEST["checkbox1"];
    $checkbox2=$_REQUEST["checkbox2"];
    if(
    $checkbox1=="helpivebeenclicked"){echo "User released the princess!";}
    if(
    $checkbox2=="noclicked") {echo "User denied clicking the frog.";}

    ?>
    if both the boxes are clicked then there isnt ne problem . But if they are unclicked then i get these creepy errors.

  • #2
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Unchecked checkboxes are not included with the form submission. Check for their existence with isset().

  • #3
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    PHP Code:
    <?php 
    $checkbox1
    = (isset($_POST["checkbox1"]))? $_POST["checkbox1"]:""
    $checkbox2= (isset($_POST["checkbox2"]))? $_POST["checkbox2"]:""
    if(
    $checkbox1=="helpivebeenclicked"){echo "User released the princess!";} 
    if(
    $checkbox2=="noclicked") {echo "User denied clicking the frog.";} 

    ?>
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)

  • #4
    New to the CF scene
    Join Date
    Aug 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks , it worked wonderfully.
    But now if i want to generate those check boxes dynamically , then how do i proceed ?

    I mean , there is a text box and the end user will put in some number to it .
    The check boxes (2 of them which i created ) must be generated in accordingly.

    Example :

    how many participants : 3


    checkbox1
    checkbox2

    checkbox1
    checkbox2

    checkbox1
    checkbox2

    Is there any way i can do that ?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •