php html
Written: Jun-2023
Handling forms posted with multiple select options
This is a walk through of the PHP & HTML code required for handling forms that have been posted with a <select>
that have the 'multiple' attribute.
The live sample below has results that highlight the problems that can be encountered with the two different options for how to handle a post, namely that if you submit a form with a multiple select with a standard non-array name (i.e. name='abc'
), then you get a single _GET result. Whereas if you submit a form with an select named as an array (i.e. name='abc[]'
) then you will get all the selected options posted within an array (i.e. $_GET['abc']
will result in an //array// of values.
TLDR
Use the following code:
html :: Simple get action form with <select>
php
Code
The relevant code can be found here:
forms-with-multiple-select-options.php
forms-with-multiple-select-options.php
Result
link Click to view a demo
square
Comments
New Comment