Jump to content

Unchecked checkbox I don't want spaces to show up


andrewst

Recommended Posts

I've got an HTML form that works for me and the PHP I've included below also works, but I get blank lines for every unchecked checkbox.  Is there a way to eliminate the spaces when unchecked boxes are submitted?

 

Code:

 

<?

$name = $_REQUEST['name'] ;

$email = $_REQUEST['email'] ;

mail( "andrewsthilaire@hotmail.com", "Wedding Music Form Completed", "Contact Person: $contact\nContact's Phone Number: $phone\nEmail: $email\nBride: $bride\nGroom: $groom\n\nWedding Date: $date\n\nCeremony Time: $ceremony_time\nCeremony Location: $ceremony_location\nCeremony Instrument Choices: $cer_instrument\nCeremony Song Place: $ceremony_placement\n\nReception Time: $reception_time\nReception Location: $reception_location\nReception Performance Times: $reception_perform\nReception - Must be setup by: $reception_setup_time\nReception Instrument Choices: $rec_instrument\nReception Music: $reception_style\n\nSelected Songs:\n$checkbox1\n$checkbox2\n$checkbox3\n$checkbox4\n$checkbox5\n$checkbox6\n$checkbox7\n$checkbox8\n$checkbox9\n$checkbox10\n$checkbox11\n$checkbox12\n$checkbox13\n$checkbox14\n$checkbox15\n$checkbox16\n$checkbox17\n$checkbox18\n$checkbox19\n$checkbox20\n$checkbox21\n$checkbox22\n$checkbox23\n$checkbox24\n$checkbox25\n$checkbox26\n$checkbox27\n$checkbox28\n$checkbox29\n$checkbox30\n$checkbox31\n$checkbox32\n$checkbox33\n$checkbox34\n$checkbox35\n$checkbox36\n$checkbox37\n$checkbox38\n$checkbox39\n$checkbox40\n$checkbox41\n$checkbox42\n$checkbox43\n$checkbox44\n$checkbox45\n$checkbox46\n$checkbox47\n$checkbox48\n$checkbox49\n$checkbox50\n$checkbox51\n$checkbox52\n$checkbox53\n$checkbox54\n$checkbox55\n$checkbox56\n$checkbox57\n$checkbox58\n$checkbox59\n$checkbox60\n$checkbox61\n$checkbox62\n$checkbox63\n$checkbox64\n$checkbox65\n$checkbox66\n$checkbox67\n$checkbox68\n$checkbox69\n$checkbox70\n$checkbox71\n$checkbox72\n$checkbox73\n$checkbox74\n$checkbox75\n$checkbox76\n$checkbox77\n$checkbox78\n$checkbox79\n$checkbox80\n$checkbox81\n$checkbox82\n$checkbox83\n$checkbox8\n$checkbox85\n$checkbox86\n$checkbox87\n$checkbox88\n$checkbox89\n$checkbox90\n$checkbox91\n$checkbox92\n$checkbox93\n$checkbox94", "From: $email" ) ;

header( "Location: formthankyou.html" );

?>

Link to comment
Share on other sites

Sample code with checkbox array

 

<?php
     /**
     * only checked cbox values are sent
     */
     if (isset($_GET['song'])) {
          $text = "Songs\n";
          foreach ($_GET['song'] as $song) {
            $text .= "$song\n";
          }
     }
     
    /**
    * echo results 
    */
    echo '<pre>';
    echo $text;
    echo '</pre>';
?>
<form>
<p>Songs</p>
<input type="checkbox" name="song[]" value="Song 1"> Song 1 <br/>
<input type="checkbox" name="song[]" value="Song 2"> Song 2 <br/>
<input type="checkbox" name="song[]" value="Song 3"> Song 3 <br/>
<input type="checkbox" name="song[]" value="Song 4"> Song 4 <br/>
<input type="checkbox" name="song[]" value="Song 5"> Song 5 <br/>
<input type="submit" name="action" value="Submit">
</form>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.