Cyberphonics Posted May 11, 2008 Share Posted May 11, 2008 Hey everyone. I have a form that lists necklaces. The point is for me to receive via email a list of the different styles the visitors like so I want them to be able to select as many as they like using checkboxes. It's not being stored in a database. I just want the text emailed to me. Everything works fine for single selections. Now I'm having trouble getting it to work for multiple selections. In the sample HTML form I put... <input type="checkbox" name="Necklaces" value="One"> One <input type="checkbox" name="Necklaces" value="Two"> Two On the net I learned to add brackets to the names so the form will know it's an array, so then I put this... <input type="checkbox" name="Necklaces[]" value="One"> One <input type="checkbox" name="Necklaces[]" value="Two"> Two In the PHP form I put this... $Necklaces = $_POST['Necklaces']; ... and selected both options to test it out. When I received the info, it just said the word "array". I searched the net again and found a suggestion to use the "serialize" function to resolve that issue, so then I wrote this... $Necklaces = serialize($_POST['Necklaces']; ) When I received the info, it had the right information in this format... (a:2:{i:0;s:3:"One";i:1;s:3:"Two";}) ...which is what the suggestion said would happen. It then said to unserialize it in order to turn that garbled information back into a usable, readable array. This is where I got stuck because I didn't understand what they were doing since they were sending their information to a database and added a bunch of other stuff like while loops, etc. I understand everything up to this point, so here's my question. How do I use the unserialize function to return the data back into a manageable text format and is there another way to accomplish this same goal without using the serialize function? I keep seeing the foreach function come up in the answers I've found. I understand what foreach does but I don't understand the syntax in order to use it. My site has dozens of styles on it at any given time, so you can see why I want to learn how to use the array instead of writing out code for each individual style. Any help would be greatly appreciated!!! Quote Link to comment https://forums.phpfreaks.com/topic/105158-email-values-posted-with-multiple-checkboxes/ Share on other sites More sharing options...
MadTechie Posted May 11, 2008 Share Posted May 11, 2008 $_POST['Necklaces'] will be an array, try this <?php $Necklaces = implode($_POST['Necklaces'], "<br>"); echo $Necklaces; //or print_r($_POST['Necklaces']); //or foreach($_POST['Necklaces'] as $Name) { echo $Name; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/105158-email-values-posted-with-multiple-checkboxes/#findComment-538395 Share on other sites More sharing options...
Cyberphonics Posted May 11, 2008 Author Share Posted May 11, 2008 Ok, I'm not a PHP person so I just went to look up what the implode function is so I'd understand what it does and the syntax. From what I gather, it lists the elements of the array and you can also use it to specify what to put in between those elements. I wanted a comma separating them so I put this... $Necklaces = implode(",",$_POST['Necklaces']); ... and then called to the $Necklaces variable as I originally had it and it worked, it sent me the options separated by commas, yay! I'll have to practice using the foreach but the implode function works great. Thank you so much. I searced the net today and all day yesterday and every answer was so complicated with so many lines of code. I kept saying there has to be an easier way to do this and you showed it to me. You know, they always say to search the net first before asking questions, but sometimes, if you just ask first, it'll save you so much time lol Thanks again!!! Quote Link to comment https://forums.phpfreaks.com/topic/105158-email-values-posted-with-multiple-checkboxes/#findComment-538413 Share on other sites More sharing options...
Cyberphonics Posted May 11, 2008 Author Share Posted May 11, 2008 Ok, now where is that "mark as solved" button because I don't see it anywhere? Quote Link to comment https://forums.phpfreaks.com/topic/105158-email-values-posted-with-multiple-checkboxes/#findComment-538419 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.