Results 1 to 6 of 6

Thread: Dealing with checkboxes in a server side script

  1. #1
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242

    Dealing with checkboxes in a server side script

    Hello

    How does one make a server side script for a form with ALOT of checkboxes?

    Does each checkbox need an ID? Then add each ID to the server side script as I would with an input?

    Or is there an easier way?

  2. #2
    Registered
    Join Date
    Apr 2006
    Posts
    184
    Depends on what you're doing.

    If you have a list of items, and you want to have a checkbox to delete each one, for instance, you can do this:

    Code:
    <input type="checkbox" name="deletethis[]" value="item1" />
    <input type="checkbox" name="deletethis[]" value="item2" />
    <input type="checkbox" name="deletethis[]" value="item3" />
    Code:
    <?php
    foreach($_POST['deletethis'] as $val) {
      // code to delete whatever it is with that ID.
    }
    ?>

  3. #3
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    Thanks for the response, I am just trying to send the selected checkboxes value(s) in an email.

  4. #4
    4x4
    Join Date
    Oct 2004
    Posts
    1,043
    Yep, use an array.

    I do the above method works great.

  5. #5
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    Hello

    Thanks to you both for the help but as a PHP halfwit I am dumbfounded.

    I have this:
    Code:
    <input class="formCheck" type="checkbox" value="Argyle" name="cities[]"> Argyle<br />
    <input class="formCheck" type="checkbox" value="Aubrey" name="cities[]"> Aubrey<br />
    <input class="formCheck" type="checkbox" value="Bartonville" name="cities[]"> Bartonville<br />
    Though there are alot more, 118 I think.

    How do I use the PHP snippet above to capture the selected ones by name and list them in the email. I have this:
    PHP Code:
    <?php
    if (!$_POST['name'] || !$_POST['address']  || !$_POST['city']  || !$_POST['workphone']) {
        
    header('Location: http://www.somesite.com/oops.html');
    } else {
        
    $message = <<<EOF
        
        Submitted by:
        
        Name:           
    {$_POST['name']}
        Company Name:   
    {$_POST['company']}
        Address:        
    {$_POST['address']}
        Address 2:      
    {$_POST['address_2']}
        City/State/Zip: 
    {$_POST['city']}
        Work Phone:     
    {$_POST['workphone']}
        FAX:            
    {$_POST['fax']}
        Email:          
    {$_POST['email']}
        Unit Size:      
    {$_POST['unitSize']}
        Occupants:      
    {$_POST['occupants']}
        Length:         
    {$_POST['lengthoflease']}
        Purchase:       
    {$_POST['purchaseHome']}
        
        My City Choices are:
           
              (
    $_POST['cities'])
          
        Additional Comments:
        
           
    {$_POST['form_comment']}
            
    EOF;

        
    mail('email address here''subject line here'$message"From: {$_POST['email']}\n");
        
    header('Location: http://www.somesite.com/thankyou.html');
    }
    ?>
    Don't laugh too hard as I said I am a programming halfwit and this is the best I can do. Everything works accept the checkboxes.

    I get this in the email:

    Submitted by:

    Name: Me
    Company Name: company
    Address: 1234 fake st
    Address 2: na
    City/State/Zip: city, state, zip
    Work Phone: 555-555-5555
    FAX: na
    Email: an email address
    Unite Size: twoBedroom
    Occupants: five
    Length: sixMonths
    Purchase: no

    My City Choices are:

    Array

    Additional Comments:

    testing
    Thanks,
    Last edited by Johnny Gulag; 09-26-2006 at 02:13 PM.

  6. #6
    Is Still Alive! Johnny Gulag's Avatar
    Join Date
    Feb 2006
    Location
    North Texas
    Posts
    242
    I figured it out, thanks though to anyone who tried and to teh 2 who responded.

Similar Threads

  1. Free Server Security Audit by Touch Support
    By TSGradyR in forum The Marketplace
    Replies: 0
    Last Post: 03-30-2005, 11:00 PM
  2. Admin Lite by Touch Support
    By TSGradyR in forum The Marketplace
    Replies: 0
    Last Post: 02-23-2005, 06:20 PM
  3. Server Side Stats & Realtime Traffic Tracking Services
    By number7 in forum General Promotion
    Replies: 6
    Last Post: 01-04-2005, 02:44 PM
  4. php: cache files on a remote server ?
    By tomek in forum Website Programming & Databases
    Replies: 2
    Last Post: 07-12-2004, 08:48 PM
  5. Replies: 2
    Last Post: 02-06-2004, 10:47 PM

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
  •