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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Nottingham, UK
    Posts
    110
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Checkboxes n PHP

    Hi Y'all,

    How is everyone doing here? Hope your all fine and having better luck with your developing skills than I am - lol!

    In my products form I want to ask users if they want to be part of a mailing list - there is a check box for them to tick, how do I pass a value of a checkbox in php?

    Sarah
    You are not a human being having a spiritual experience, your a spiritual
    being having a human experience.

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If I understand correctly, you dont need php, more just HTML formatting...

    Code:
    Yes! Add me to the list! <input type="radio" name="addtolist" value="yes" checked="checked" />
    
    No, dont add me <input type="radio" name="addtolist" value="no" />
    Then the $_GET['addtolist'] variable will be either yes or no, depending on which they checked. You can use this info to decide whether you add them to the list or not.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually - and I'm pretty sure here, checkboxes cannot pass values - they only pass 'on' if they are checked or 'off' if unchecked.

    so...

    yes: <input type="checkbox" name="a2l[]" />
    no: <input type="checkbox" name="a2l[]" />

    would send to

    $_POST['a2l'][0] = 'on' if yes checked
    $_POST['a2l'][1] = 'on' if no checked

    as you probably know, naming them the same (whether as an array name or not) means that only one can be checked and all others unchecked.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No, they can, because I use a method like this in my forum.

    Yes, I do know that only one can be checked, but This is good in this case, as you dont want someone to be able to subscribe and not subscribe at the same time.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so you can - sure I couldn't last time I played - odd.

    subnote: just found out - it's radio buttons that can be grouped by name so only one can be selected - doesn't appear to work for checkboxes.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.

  • #6
    Registered User
    Join Date
    Feb 2003
    Location
    Berkshire, UK
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <input type="checkbox" name="addtomailinglist" value="on" />

    PHP Code:
    if ($addtomailinglist=='on') {
      
    // code here

    i can't remember what value it will return if the checkbox is not ticked.

  • #7
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont think it will return any value.

    Be sure to use $_GET['addtomailinglist'] not $addtomailinglist


  •  

    Posting Permissions

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