Results 1 to 2 of 2

Thread: Handling Multiple Checkbox Values

  1. #1
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Handling Multiple Checkbox Values

    Hi. I have created an HTML form that includes a few checkbox groups that I would like the visitors to be able to check all values that apply to them. I have searched online and have tried figuring out a way to have multiple values handled and emailed to my account. I do not know that much about PHP so can someone PLEASE help me. Thanks so much in advance.

    Here is what I have so far:

    (HTML form)

    Code:
    <form action="volunteer-form2.php" method="post">
    <table width="595" class="style8">
      <tr>
        <td colspan="3">Your Interested In Volunteering For: (check all that apply)</td>
      </tr>
      <tr>
        <td width="177" height="30"><input type="checkbox" name="interested[]" value="Home Repairs" /> Home Repairs</td>
        <td width="177"><input type="checkbox" name="interested[]" value="Yard Maintenance" /> Yard Maintenance</td>
        <td width="219"><input type="checkbox" name="interested[]" value="Gardening" /> Gardening</td>
        </tr>
      <tr>
        <td height="30"><input type="checkbox" name="interested[]" value="Fund Raising" /> Fund Raising</td>
        <td><input type="checkbox" name="interested[]" value="Special Events" /> Special Events</td>
        <td><input type="checkbox" name="interested[]" value="Public Relations" /> Public Relations</td>
        </tr>
      <tr>
        <td height="30"><input type="checkbox" name="interested[]" value="Driving" /> Driving</td>
        <td><input type="checkbox" name="interested[]" value="Mentoring Children" /> Mentoring Children</td>
        <td><input type="checkbox" name="interested[]" value="Special Programs For Families" /> Special Programs For Families</td>
        </tr>
      <tr>
        <td height="30" colspan="3"><input type="checkbox" name="interested[]" value="Organizing Supplies" /> Organizing Supplies In Our Warehouse Facilities</td>
      </tr>
      <tr>
        <td height="10" colspan="3">&nbsp;</td>
      </tr>
    </table>
    <input type="submit" name="submit" value="Submit" />
    </form>
    (PHP Code)

    Code:
    <?php  
    
    $to = "myemail@hotmail.com" ;  
    $from = $_REQUEST['email'] ;  
    $name = $_REQUEST['firstname'] ;  
    $headers = "From: $from";  
    $subject = "Web Inquiry";
    
    $fields = array(); 
    $fields{"firstname"} = "Name";  
    $fields{"lastname"} = "Last Name";  
    $fields{"street"} = "Address";  
    $fields{"city"} = "City";  
    $fields{"state"} = "State";  
    $fields{"zip"} = "Zip"; 
    $fields{"phone"} = "Phone Number";  
    $fields{"email"} = "Email Address";
    $fields{"contactpreference"} = "Contact Preference";
    $fields{"contacttime"} = "Best Time To Contact";
    $fields{"email"} = "Email Address";
    $fields{"learn"} = "Learned About The Program";
    $fields{"interested"} = "Interested In";
    $fields{"available"} = "Available";
    $fields{"medicalconditions"} = "Medical Conditions";
    $fields{"emergencycontact"} = "Emergency Contact"; 
    $fields{"contactphone"} = "Emerency Contact Phone"; 
    $fields{"contactemail"} = "Emergency Contact Email"; 
    $fields{"comments"} = "Question or Comment";
    
    $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ 	$body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }   
    
    $headers2 = "From: noreply@mysitename.com";  
    $subject2 = "Thank you for contacting us";  
    $autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible. If you have any more questions, please visit our website at www.mysitename.com";  
    
    
    if($from == '') {print "You have not entered an email, please go back and try again";}  
    else {  
    $send = mail($to, $subject, $body, $headers);  
    $send2 = mail($from, $subject2, $autoreply, $headers2);  
    if($send)  {header( "Location: thankyou.html" );}  
    else  
    {print "We encountered an error sending your mail, please notify our webmaster at myemail@hotmail.com"; }  
    }} 
    
    ?>
    Last edited by djr33; 04-09-2010 at 03:12 PM. Reason: added [code] tags

  2. #2
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    I am not seeing how the form and the php are related. The values you are asking for in the form don't match up in any way that I can see to the php code you have posted.
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •