SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Location
    Westville, Durban, South Africa
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php - no blank variables

    I have an enquiry form that has a list of "product interest" checkboxes.

    From the form I use action="post" and I use my php mail handler to email my data (a) to me and (b) as confirmation to the client using $_POST[".."] etc. to get the variables from the form.

    The "product interest" list has 15 or so items and they can all be selected, just one, or any combination in between.

    How do I send the "checked" items only, without having to test if data is there using 15 off "if" statements ? Currently I send them all and that includes blanks !

  2. #2
    hi galen's Avatar
    Join Date
    Jan 2006
    Location
    New Haven, CT
    Posts
    1,228
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    name all the checkboxes something like checkbox['something']. then loop through the checkbox array.

    PHP Code:
    foreach($checkbox as $key => $val) {
        
    $str .= $key ': ' $val "\r\n";

    the mail $str to yourself.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Location
    Westville, Durban, South Africa
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    galen - Many thanks. It works like a dream. Took me a while to figure out that the checkbox array and the value declared in the HTML form could be different, I ended up with:

    <input type="checkbox" name="ProductInterest[Software]" value="eNature" id="Interest"> PDA software - eNature software<br>

    // check all product interest checkboxes
    $checkbox = $_POST['ProductInterest'];
    foreach($checkbox as $key => $value)
    {
    $str1 .= $key . " : " . $value . "<br><br />";
    }

    Great help....


Bookmarks

Posting Permissions

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