wolfcry Posted May 30, 2007 Share Posted May 30, 2007 Hey all! Nice to meet you and love the site I've been learning PHP for about 6 months and have hit a brick wall and need help please. What I want to do is pass multiple checkbox values from a form on an HTML page to another page (Thank you page) where it can be viewed if it was selected (checked). I know I need to "Get" the information from the quiry string after the information has been submitted but I'm lost on how to exactly set this up so it works properly. EXAMPLE: <input type="checkbox" name="passon[]" value="Test 1">Test 1 <input type="checkbox" name="passon[]" value="Test 2">Test 2 <input type="checkbox" name="passon[]" value="Test 3">Test 3 <input type="checkbox" name="passon[]" value="Test 4">Test 4 <input type="checkbox" name="passon[]" value="Test 5">Test 5 If the user checks test 1, 2, and 4 for example, I want those values to be passed to the thank you page where they can be seen as having been checked such as: Test(s) you're willing to take: Test 1, Test 2, Test 4 I have tried everything that I could think of and cannot get this to work so all help will be greatly appreciated. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/ Share on other sites More sharing options...
spode Posted May 30, 2007 Share Posted May 30, 2007 My suggestion would be to use $_POST instead, and then on the next page (or whatever page handles the form), simply combine all of those values into an array. So you could do: <?php $array = implode ($_POST['$button1'], $_POST['$button4'], $_POST['$button']); echo $array; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265224 Share on other sites More sharing options...
per1os Posted May 30, 2007 Share Posted May 30, 2007 thankyou.php <?php if (isset($_POST['passon'])) { if (is_array($_POST['passon'])) { $tests = "You are willing to take "; foreach ($_POST['passon'] as $val) { $tests .= $val . ' '; } $tests .= '!'; } } echo 'Hello Jack!<br />' . $tests; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265226 Share on other sites More sharing options...
wolfcry Posted May 30, 2007 Author Share Posted May 30, 2007 wow, wicked response time guys! You both should receive 'fastest customer service award Frost110, your code worked beautifully....I especially loved the Hello Jack! quip lol. Thanks a bunch you two..the help was highly appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265245 Share on other sites More sharing options...
wolfcry Posted May 30, 2007 Author Share Posted May 30, 2007 Ok, everything is working as it should so thank you. I have one other question if I may, If I wanted to customize it so the values appeared in a column format such as the example below, how do I modify this code to do that? EXAMPLE: Test 1 Test 2 Test 3 etc. etc. I've been experimenting and getting other tweaks and things to work little by little, but I'm hung up on this. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265268 Share on other sites More sharing options...
Dragen Posted May 31, 2007 Share Posted May 31, 2007 <?php if (isset($_POST['passon'])) { if (is_array($_POST['passon'])) { $tests = "You are willing to take "; foreach ($_POST['passon'] as $val) { $tests .= $val . '<br />'; } $tests .= '!'; } } echo 'Hello Jack!<br />' . $tests; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265278 Share on other sites More sharing options...
wolfcry Posted May 31, 2007 Author Share Posted May 31, 2007 Thanks Dragen, Unfortunately I've already tried that and re-tried it after you suggested it and the code still presents the information in a string rather than a column. Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265285 Share on other sites More sharing options...
Dragen Posted May 31, 2007 Share Posted May 31, 2007 I can't think why.. just a silly suggesstion but try changing this line: $tests = "You are willing to take "; to this: $tests = 'You are willing to take '; might be confusing the php or something.. (probably not though ) You should even be able to use a table for it like this: <?php if (isset($_POST['passon'])) { if (is_array($_POST['passon'])) { $tests = 'You are willing to take'; $tests .= '<table align="left" width="100%" border="0" cellpadding="0" cellspacing="0">'; foreach ($_POST['passon'] as $val) { $tests .= '<tr><td align="left">' . $val . '</td></tr>'; } $tests .= '</table>'; } } echo 'Hello Jack!<br />' . $tests; ?> Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265304 Share on other sites More sharing options...
wolfcry Posted May 31, 2007 Author Share Posted May 31, 2007 Ok, the table integration didnt cause any problems when testing the form but when viewing the source code after submission, the table that was newly integrated didnt even show up which means it didnt even get created and the output was still in one single string. Also, I adjusted your width="100%" to 200px to see if there was a size reduction and there wasnt. So that means the table actually wasnt created. I tried your suggestion of changing the " to ' but that didnt make a difference either. Not really sure whats going on lol Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265311 Share on other sites More sharing options...
Dragen Posted May 31, 2007 Share Posted May 31, 2007 strange.. I can't figure out why it's not working :-\ Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265313 Share on other sites More sharing options...
wolfcry Posted May 31, 2007 Author Share Posted May 31, 2007 Me neither but I would really find a work-a-round that will actually allow me to display this in column format. I'm starting to get bald spots from pulling my hair out lol Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265352 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 Just a shot in the dark, have you viewed the source to see if the script is even trying to display anything? Are you making sure that you are still posting data? My test code is: <?php $_POST['passon'] = array("test1", "test3", "test5"); if (isset($_POST['passon'])) { if (is_array($_POST['passon'])) { $tests = 'You are willing to take'; $tests .= '<table align="left" width="100%" border="0" cellpadding="0" cellspacing="0">'; foreach ($_POST['passon'] as $val) { $tests .= '<tr><td align="left">' . $val . '</td></tr>'; } $tests .= '</table>'; } } echo 'Hello Jack!<br />' . $tests; ?> Output was Hello Jack!<br />You are willing to take <table align="left" width="100%" border="0" cellpadding="0" cellspacing="0"> <tr><td align="left">test1</td></tr> <tr><td align="left">test3</td></tr> <tr><td align="left">test5</td></tr> </table> Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265537 Share on other sites More sharing options...
wolfcry Posted May 31, 2007 Author Share Posted May 31, 2007 Yep, checking everything. Now if I use the exact code above to test the output, it works. It outputs into a table. But if I use a modified version of the code, it doesn't create the table and it outputs into a single string. Here is a modified version. I have two forms that need to use this, the test form with the test information and a form with the following. I am trying to set up this one right now because its higher priority. <input type="checkbox" name="services[]" value="Marketing and Advertising">Marketing & Advertising <input type="checkbox" name="services[]" value="Search Engine Optimization">Search Engine Optimization <input type="checkbox" name="services[]" value="Web Optimization"> Web optimization <input type="checkbox" name="services[]" value="Form Hosting">Form Hosting <input type="checkbox" name="services[]" value="Web Hosting">Web Hosting <input type="checkbox" name="services[]" value="Web Consultation">Web Consultation <input type="checkbox" name="services[]" value="All"> All I changed the information on the PHP code to read as: <?php if (isset($_POST['services'])) { if (is_array($_POST['services'])) { $services = "Other services you are interested in"; foreach ($_POST['services'] as $val) { $services .= $val . '<br /> '; } $services .= '!'; } } echo 'Other services you are interested in<br />' . $services; ?> I had to change the $tests variables to $services because nothing was showing up. Not sure why, considering the variable should be global and not restricted. But I might be forgetting something. Also, I changed the echo 'hello jack" to be what it is, because I didn't want the Hello Jack! there and because if I used: echo $services; to print out "Other services you are interested in" nothing showed up. Again, I'm probably overlooking something small. When I use: <?php $_POST['passon'] = array("test1", "test3", "test5"); if (isset($_POST['passon'])) { if (is_array($_POST['passon'])) { $tests = 'You are willing to take'; $tests .= '<table align="left" width="100%" border="0" cellpadding="0" cellspacing="0">'; foreach ($_POST['passon'] as $val) { $tests .= '<tr><td align="left">' . $val . '</td></tr>'; } $tests .= '</table>'; } } echo 'Hello Jack!<br />' . $tests; ?> It prints exactly as it should. Including the "Willing to take" part. But when I make the adjustments (using different variable names such as $services and changing the passon tag to services etc.) and delete the: $_POST['passon'] = array("test1", "test3", "test5"); It again goes back to outputting into a single string. Now if I readd the array but change the tags into other titles such as $_POST['passon'] = array("Marketing", "SEO", "Web"); It again, outputs into the table but does not show anything that is actually selected. Only the arrays that I am forcing it to print. Again, I'm sure I'm just missing something basic or doing something that is causing the php to conflict, but everything is working as it should with the modified code I have but I just cannot get it to parse in a tabled structure as demonstrated here. Thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-265906 Share on other sites More sharing options...
wolfcry Posted June 4, 2007 Author Share Posted June 4, 2007 Still trying to get this to work and I cant. Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-267752 Share on other sites More sharing options...
wolfcry Posted June 8, 2007 Author Share Posted June 8, 2007 Ok, I got it to work alittle better but I still cannot get it to parse into a table nor format itself into a column formation. Any suggestions are very welcome. Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-271032 Share on other sites More sharing options...
DyslexicDog Posted June 8, 2007 Share Posted June 8, 2007 Ok, I got it to work alittle better but I still cannot get it to parse into a table nor format itself into a column formation. Any suggestions are very welcome. Sounds like a problem with your output html can you post the html for the page your are viewing? Quote Link to comment https://forums.phpfreaks.com/topic/53657-passing-checkbox-values-to-another-page/#findComment-271126 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.