By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,034 Members | 1,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,034 IT Pros & Developers. It's quick & easy.

Having trouble with Multiple Select box in form processor.

P: 2
My form processor is giving me a bit of trouble for some unknown reason. I was sure I had both my form and my processor correctly scripted. I am pretty new to this though. All of the fields except for the multiple select box are functioning properly. If anyone could help me with this, I'd really appreciate it. The page where the form is located can be found HERE

Here is the script for my multiple select box in my form:

Expand|Select|Wrap|Line Numbers
  1. <span style="font-style: italic">Hold
  2. CTRL
  3. for
  4. multiple
  5. selections</span><br />
  6. <label for="open_slots[]"></label>
  7. <select name="open_slots[]" size="6" multiple="multiple" id="open_slots[]">
  8.   <option value="Monday 2a-6a">Monday  2a-6a</option>
  9.   <option value="Tuesday 2a-6a">Tuesday  2a-6a</option>
  10.   <option value="Wednesday 2a-6a">Wednesday  2a-6a</option>
  11.   <option value="Thursday 2a-6a">Thursday  2a-6a</option>
  12.   <option value="Friday 2a-6a">Friday  2a-6a</option>
  13.   <option value="Saturday 2a-8a">Saturday  2a-8a</option>
  14.   <option value="Sunday 2a-8a">Sunday  2a-8a</option>
  15.   <option value="Monday 10a-2p">Monday  10a-2p</option>
  16.   <option value="Tuesday 10a-2p">Tuesday  10a-2p</option>
  17.   <option value="Wednesday 10a-2p">Wednesday  10a-2p</option>
  18.   <option value="Thursday 10a-2p">Thursday  10a-2p</option>
  19.   <option value="Friday 10a-2p">Friday  10a-2p</option>
  20.   <option value="Saturday 3p-7p">Saturday  3p-7p</option>
  21.   <option value="Sunday 3p-7p">Sunday  3p-7p</option>
  22.   <option value="Monday 2p-6p">Monday  2p-6p</option>
  23.   <option value="Tuesday 2p-6p">Tuesday  2p-6p</option>
  24.   <option value="Wednesday 2p-6p">Wednesday  2p-6p</option>
  25.   <option value="Thursday 2p-6p">Thursday  2p-6p</option>
  26.   <option value="Friday 2p-6p">Friday  2p-6p</option>
  27.   <option value="Saturday 7p-10">Saturday  7p-10</option>
  28.   <option value="Sunday 7p-10">Sunday  7p-10</option>
  29.   <option value="Monday 6p-10p">Monday  6p-10p</option>
  30.   <option value="Tuesday 8p-2a">Tuesday  8p-2a</option>
  31.   <option value="Wednesday 6p-10p">Wednesday  6p-10p</option>
  32.   <option value="Thursday 8p-2a">Thursday  8p-2a</option>
  33.   <option value="Friday 6p-10p">Friday  6p-10p</option>
  34.   <option value="Saturday 10p-2a">Saturday  10p-2a</option>
  35.   <option value="Sunday 10p-2a">Sunday  10p-2a</option>
  36.   <option value="Monday 10p-2a">Monday  10p-2a</option>
  37.   <option value="Wednesday 10p-2a">Wednesday  10p-2a</option>
  38.   <option value="Friday 10p-2a">Friday  10p-2a</option>
  39. </select>
  40. <br />
Here is my processor script:

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $ToEmail = 'user@example.com';
  3. $ToSubject  = 'NEW DJ APPLICATION from WWRN Webpage';
  4.  
  5. $email = $_POST['email'];
  6. $fullname = $_POST['fullname'];
  7. $phone = $_POST['phone'];
  8. $website = $_POST['website'];
  9. $position = $_POST['position'];
  10. $resume = $_POST['resume'];
  11. $prior_experience = $_POST['prior_experience'];
  12. $broadband = $_POST['broadband'];
  13. $startdate = $_POST['startdate'];
  14. $work_sample = $_POST['work_sample'];
  15. $show_name = $_POST['show_name'];
  16. $cohost = $_POST['cohost'];
  17. $website = $_POST['website'];
  18. $open_slots = $_POST['open_slots'];
  19.  
  20.  
  21. $EmailBody =   "Email: $email\n
  22. Name: $fullname\n
  23. Phone: $phone\n
  24. Website: $website\n
  25. Position Applying For: $position\n
  26. Resume: $resume\n
  27. Prior Experience: $prior_experience\n
  28. Broadband: $broadband\n
  29. Start Date: $startdate\n
  30. Link to Sample of Work: $work_sample\n
  31. Desired Show Name: $show_name\n
  32. Co-Hosts/DJs: $cohost\n
  33. Desired Open Slot: $open_slots\n";
  34.  
  35. $Message = $EmailBody;
  36.  
  37.  
  38. $headers .= "Content-type: text; charset=utf-8\r\n";
  39. $headers .= "From:".$email."\r\n";
  40.  
  41. mail($ToEmail,$ToSubject,$Message, $headers);
  42.  
  43. /* Resulrs rendered as HTML */
  44.  
Whenever the form gets processed, all of the enter text fields and radio buttons come through just fine. But the selections from my multi-select box are only returned as "Array." I don't see where I went wrong. Can you tell me how to fix this, please?
Mar 12 '10 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Hey.

That is because the values selected in a multi-select box are returned as an array, and when you try to print an array as a string, it simply prints "Array".

What you need to do is create a string from the array values and print that. The implode function can help there.
Expand|Select|Wrap|Line Numbers
  1. $open_slots_str = implode(', ', $open_slots);
  2. echo $open_slots_str;
  3. // Prints something like:
  4. //  First value, Second value, Third value
Mar 12 '10 #2

P: 2
Thank you. That was all that I needed. You really know your stuff. I nixed the "echo $open_slots;" because I don't need that info showing up in my results page and it works perfectly. I really appreciate your help. This has saved me a lot trouble and headache. I've been working on this form for the past 3 days. I don't have a lot of money to spare but I figure since you did this for free that I'd be willing to make a donation to your PP account. Just PM me if you're interested. Thanks again.
Mar 12 '10 #3

P: 1
This solved my problem too! I knew it had to be a simple fix.... thanks a TON!
May 24 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.