Skip to main content
Participating Frequently
June 20, 2009
Answered

select multiple options in form

  • June 20, 2009
  • 3 replies
  • 616 views

Hi

i have one little problem the grade or interest and specialties should be able to select multiple options and i have set this up but when i test it the information coming back on email shows only only on selection for these fields. Anyone know why. http://www.locumexpress.ie/online%20reg.php

Thanks

Natasha

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer David_Powers

When form fields allow multiple choices, the form must submit them as an array. To do this, add an empty pair of square brackets after the name attribute.

The name attribute of form elements should not contain any spaces, so this is invalid:

<select name="Grade of Interest" 

You should replace it with something like this:

<select name="Grade_of_interest[]" 

This submits the values as an array, so you need to use implode() to convert them back to a string:

if (isset($_POST['Grade_of_interest'])) {

  $_POST['Grade_of_interest'] = implode(', ', $_POST['Grade_of_interest'])

}

I also notice that you're using spaces in your file names. You should never put spaces in file or folder names on a website. The reason it's working now is because your site is hosted on a Windows server. If the site is ever moved to a Linux server (and most sites are hosted on Linux), it will break. Also, the %20 that represents the space in the middle of the URL looks ugly.

3 replies

David_Powers
David_PowersCorrect answer
Inspiring
June 20, 2009

When form fields allow multiple choices, the form must submit them as an array. To do this, add an empty pair of square brackets after the name attribute.

The name attribute of form elements should not contain any spaces, so this is invalid:

<select name="Grade of Interest" 

You should replace it with something like this:

<select name="Grade_of_interest[]" 

This submits the values as an array, so you need to use implode() to convert them back to a string:

if (isset($_POST['Grade_of_interest'])) {

  $_POST['Grade_of_interest'] = implode(', ', $_POST['Grade_of_interest'])

}

I also notice that you're using spaces in your file names. You should never put spaces in file or folder names on a website. The reason it's working now is because your site is hosted on a Windows server. If the site is ever moved to a Linux server (and most sites are hosted on Linux), it will break. Also, the %20 that represents the space in the middle of the URL looks ugly.

tashmacAuthor
Participating Frequently
June 23, 2009

Thanks for that

David_Powers
Inspiring
June 20, 2009

Please post PHP-related questions in the correct forum: Dreamweaver Application Development, where your thread has been moved.