andrewst Posted February 26, 2007 Share Posted February 26, 2007 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( "[email protected]", "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 https://forums.phpfreaks.com/topic/40146-unchecked-checkbox-i-dont-want-spaces-to-show-up/ Share on other sites More sharing options...
mbtaylor Posted February 26, 2007 Share Posted February 26, 2007 just test first if the checkbox var is empty or not before including it. You are getting the blank line from the \n. if (!empty($checkbox1))$message .= "$checkbox1\n"; \\ and so on with all your vars mail ($message......) Link to comment https://forums.phpfreaks.com/topic/40146-unchecked-checkbox-i-dont-want-spaces-to-show-up/#findComment-194230 Share on other sites More sharing options...
Archadian Posted February 26, 2007 Share Posted February 26, 2007 all i can say about your code andrewst is... "what in the hell???" lol Link to comment https://forums.phpfreaks.com/topic/40146-unchecked-checkbox-i-dont-want-spaces-to-show-up/#findComment-194240 Share on other sites More sharing options...
Archadian Posted February 26, 2007 Share Posted February 26, 2007 first of all make $checkbox an array() then check that array to see if anything is empty, if it is then don't display it and then go on to the next checkbox. checkboxes go by "on" and "off" Link to comment https://forums.phpfreaks.com/topic/40146-unchecked-checkbox-i-dont-want-spaces-to-show-up/#findComment-194257 Share on other sites More sharing options...
andrewst Posted February 26, 2007 Author Share Posted February 26, 2007 I don't know what's so funny... I can't say I'm a pro or anything if you're laughing at how rudimentary my code is. All I know is that it works and needed this little adjustment. I'll give your suggestions a try. Thanks Link to comment https://forums.phpfreaks.com/topic/40146-unchecked-checkbox-i-dont-want-spaces-to-show-up/#findComment-194593 Share on other sites More sharing options...
Barand Posted February 26, 2007 Share Posted February 26, 2007 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 https://forums.phpfreaks.com/topic/40146-unchecked-checkbox-i-dont-want-spaces-to-show-up/#findComment-194725 Share on other sites More sharing options...
Archadian Posted February 26, 2007 Share Posted February 26, 2007 Nah i wants laughing at your code, i was half asleep when i posted that lol. Hopefully the array() helped out and fixed it Link to comment https://forums.phpfreaks.com/topic/40146-unchecked-checkbox-i-dont-want-spaces-to-show-up/#findComment-194810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.