SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display Selected checkbox on form submit

    I'm trying to create an email submisison form. I'm getting all of the text and number fields to show up fine in the e-mail I received after submitting the form. However, I have three groups of checkboxes and another single check box that wil not return results in the e-mail.

    I used

    $field = array();

    to display the text/number fields. I tried a few different ways to display the checkbox, but to no avail.

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Can u paste the HTML for the checkboxes.

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <td align="center"><h4>Portrait Packages</h4>
            <!--Please select the package(s) you wish to purchase.--></td>
            
              
              <td>
              	<input type="checkbox" name="package[]" value="bronze"> Bronze - $62.95<br>
                <input type="checkbox" name="package[]" value="silver"> Silver - $65.95<br>
              	<input type="checkbox" name="package[]" value="gold"> Gold - $67.95<br>
                <input type="checkbox" name="package[]" value="platinum"> Platinum - $69.95<br>
                <input type="checkbox" name="package[]" value="unbelievable"> Unbelievable - $83.95<br>
              	<input type="checkbox" name="package[]" value="astonishing"> Astonishing - $86.95<br>
    
              </td>
            </tr>
             <tr>
            <td align="center"><h4>Additional Prints with Package Purchase</h4>
     </td>
            
              
              <td>
              	<input type="checkbox" name="print[]" value="three_by_five"> Four 3x5's - $16.00<br>
                <input type="checkbox" name="print[]" value="five_by_seven"> Two 5x7's - $16.00<br>
              	<input type="checkbox" name="print[]" value="eight_by_ten"> One 8x10 - $16.00<br>
                <input type="checkbox" name="print[]" value="sixteen_wallets"> 16 Wallets - $16.00<br>
                <input type="checkbox" name="print[]" value="twentyfour_wallets"> 24 Wallets - $30.95<br>
              	<input type="checkbox" name="print[]" value="ten_by_thirteen"> One 10x13 - $21.00<br>
    
              </td>
            </tr>
            <tr>
            <td align="center"><h4>Additional Prints without Package Purchase</h4>
     </td>
             <td>
              	<input type="checkbox" name="print_nopack[]" value="three_by_five_nopack"> Four 3x5's - $40.95<br>
    
                <input type="checkbox" name="print_nopack[]" value="five_by_seven_nopack"> Two 5x7's - $44.95<br>
              	<input type="checkbox" name="print_nopack[]" value="eight_by_ten_nopack"> One 8x10 - $46.95<br>
                <input type="checkbox" name="print_nopack[]" value="sixteen_wallets_nopack"> 16 Wallets - $25.95<br>
                <input type="checkbox" name="print_nopack[]" value="twentyfour_wallets_nopack"> 24 Wallets - $30.95<br>
              	<input type="checkbox" name="print_nopack[]" value="ten_by_thirteen_nopack"> One 10x13 - $50.95<br>
    
              </td>
            </tr>
            <tr>
              <td align="right" valign="top"><label for="message">Special Instructions:</label>&nbsp;&nbsp;</td>
              <td><textarea name="message" id="message" cols="50" rows="3"></textarea></td>
            </tr>

  4. #4
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    In your email body, you would do something like this:

    PHP Code:
    $body .= "Portrait Packages\n===========\n".implode("\n", (array) $_POST['package'])."\n\n";
    $body .= "Additional Prints with Package Purchase\n===========\n".implode("\n", (array) $_POST['print'])."\n\n"
    If you want to retrieve the individual check boxes, you can do print_r($_POST['package']) to see which were checked.

    One thing I would recommend changing is the value="" to the human friendly version, like instead of

    value="three_by_five" change it to value="Four 3x5's - $16.00"

  5. #5
    SitePoint Enthusiast
    Join Date
    Nov 2010
    Posts
    80
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by wonshikee View Post
    In your email body, you would do something like this:

    PHP Code:
    $body .= "Portrait Packages\n===========\n".implode("\n", (array) $_POST['package'])."\n\n";
    $body .= "Additional Prints with Package Purchase\n===========\n".implode("\n", (array) $_POST['print'])."\n\n"
    If you want to retrieve the individual check boxes, you can do print_r($_POST['package']) to see which were checked.

    One thing I would recommend changing is the value="" to the human friendly version, like instead of

    value="three_by_five" change it to value="Four 3x5's - $16.00"
    Thank you, that did the trick. I have another question. I want to rearrange the submission e-mail. The way it is right now in the e-mail I receive I have to list all of the $fields before the $body. I want to arrange how the e-mail appears, but I'm not sure how.

    I'm assuming it has to do with this line of code, which I copied and pasted from a tutorial.

    PHP Code:
    $body "We have received the following information:\n\n"; foreach($fields as $a => $b){     $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 
    The top of the e-mail says "We have received the following information" which is perfect. I'm assuming because the fields array is called first is the reason I have to list all of those before the $body which is called second. Is there a way to split up the field arrays around the $body?


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
  •