Jump to content

Multi-select list values on POST


qwerty234

Recommended Posts

Hi,

 

In my HTTP header I've collected the following values from a multi-select list after my POST:

project_list=community_name&project_list=project_number&project_list=map_letter&project_list=home_type

 

Here's my PHP code to loop thru the project_list after the POST. For some reason my array $a is not being populated, do you see why?

 

     
$a = array();

foreach ($_POST['project_list'] as $selected) 
{
        if ($selected == 'community_name'){
                    $a[] = "projects.project_name ";
        }

        if ($selected == 'project_number'){
                    $a[] = "projects.project_number ";
        }

        if ($selected == 'map_letter'){
	      $a[] = "projects.map_letter ";
        }

        if ($selected == 'home_type'){
                    $a[] = "home_types.home_type ";
        }
.
.
.

Link to comment
Share on other sites

Guest prozente

If I understand what you're trying to do correctly then put in your code

 

echo '<pre>'
print_r ($_POST);
echo '</pre>';

 

then submit the form and look at the results. I'm guessing you didn't set the input tags as an array in the html.

 

Also a switch would be better instead of all of those if statements since you are only looking at a single variable.

 

 

Link to comment
Share on other sites

I see two things wrong with the following line based on what I'm reading:

 

project_list=community_name&project_list=project_number&project_list=map_letter&project_list=home_type

 

If this is what you're seeing in the URL after you submit your form, then you are passing your form variables using the $_GET array, not the $_POST array. Change your form submit method to "POST" if you are not already.

 

Additionally, if you're trying to pass a multi select list from an HTML form, you have to append brackets to the end of the form element name. So instead of using "project_list" for the name, you would need to use "project_list[]". Otherwide, each time a"project_list" value was defined, it would overwrite the existing value because the value is being treated as a string. If you use "project_list[]", then each new definition will add an element to the array, as the values would be treated as array elements.

 

Good luck!

 

;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.