Form Select element with multipart/form-data enctype

397 Views Asked by At

I'm using select element with multiple selections and image field for my Ajax form. For submitting image, I've to use form enctype="multipart/form-data". When I submit the form, the post data for my multiple select element named "business_type" is as follow since I select three options from select element.

Content-Disposition: form-data; name="business_type"    
Manufacturer
-----------------------------212041485118126
Content-Disposition: form-data; name="business_type"   
Wholesaler
-----------------------------212041485118126
Content-Disposition: form-data; name="business_type"    
Trading House

Now, in my $_REQUEST array (In PHP), I'm receiving only the last item as it is obvious from above-mentioned post data. How can I get the other selected values?

1

There are 1 best solutions below

0
saiid On

Just a simple trick that worked for me is by replacing the select element name name="business_type" with an array as follow.

Replace

<select name="business_type" multiple required>

with

<select name="business_type[]" multiple required>

So getting the array of all selected fields in post data.