How does php handle form with multiple selection?

I have a html form which has a select list box from which you can select multiple values because its multiple property is set to multiple. Consider form method is 'GET'. The html code for the form is as follows:


    
    Untitled Document
    
    
    
      
Multiple Selection   eleven twelve thirette fourteen fifteen sixteen seventeen eighteen nineteen twenty
 

I want to display the selected values in select list box on display.php page. So how are the selected values accessed on display.php page using $_GET[] array.

asked Mar 9, 2010 at 7:27

Param-GanakParam-Ganak

5,62717 gold badges49 silver badges62 bronze badges

1

If you want PHP to treat $_GET['select2'] as an array of options just add square brackets to the name of the select element like this:

Kobi

132k41 gold badges253 silver badges284 bronze badges

answered Nov 4, 2010 at 11:33

Use the following program for select the multiple values from select box.

multi.php


value.php


answered Mar 9, 2010 at 8:31

rekha_srirekha_sri

2,5591 gold badge23 silver badges27 bronze badges

0

    

Untitled Document



  
Multiple Selection   eleven twelve thirette fourteen fifteen sixteen seventeen eighteen nineteen twenty
 

You can iterate it directly like this

foreach [$_GET['select2'] as $value]
    echo $value."\n";

or you can do it like this

$selectvalue=$_GET['select2'];
foreach [$selectvalue as $value]
    echo $value."\n"; 

answered Dec 21, 2013 at 6:10

VivekVivek

1,40818 silver badges27 bronze badges

This will display the selected values:


Gigala

1432 silver badges10 bronze badges

answered May 27, 2012 at 8:14

ahmedahmed

751 silver badge1 bronze badge

1

// CHANGE name="select2" TO name="select2[]" THEN

answered Jun 18, 2013 at 20:09

RynikaRynika

511 silver badge2 bronze badges

You could do like this too. It worked out for me.


     
        Last 1 Week
        Last 2 Week 
        Last 3 Week
         Last 4 Week
          Last 5 Week
           Last 6 Week
    
      

Then take the multiple selection from following PHP code below. It print the selected multiple values accordingly.

$shift=$_POST['selectDuration'];

print_r[$shift];

answered Aug 16, 2016 at 4:54

Du-LacosteDu-Lacoste

10.2k2 gold badges62 silver badges49 bronze badges

I fix my problem with javascript + HTML. First i check selected options and save its in a hidden field of my form:

for[i=0; i < form.select.options.length; i++]
   if [form.select.options[i].selected]
    form.hidden.value += form.select.options[i].value;

Next, i get by post that field and get all the string ;-] I hope it'll be work for somebody more. Thanks to all.

answered Apr 16, 2013 at 19:25

DrakoDrako

7491 gold badge8 silver badges22 bronze badges

2

foreach [$_POST["select2"] as $selectedOption]
{    
    echo $selectedOption."\n";  
}

answered Oct 7, 2013 at 5:51

SwRSwR

5781 gold badge7 silver badges20 bronze badges

0

How does PHP handle form with multiple selections?

Given a list of items and the task is to retrieve the multiple selected value from a select box using PHP. Use multiple attribute in HTML to select multiple value from drop down list.

How do you handle multiple selects?

Selecting multiple options vary in different operating systems and browsers: For windows: Hold down the control [ctrl] button to select multiple options. For Mac: Hold down the command button to select multiple options.

How get multiple selected values from dropdown in PHP?

How to Get Multiple Selected Values of the Select Box in PHP.
On windows, you should hold down + CTRL key for selecting the multiple option..
On Mac, it is necessary to hold down the command key for selecting the multiple option..

How do I get all selected values of a multiple select box?

There are several ways in JavaScript to return the selected values in a multi-select dropdown..
Using for…of statement. ... .
Using filter[] with map[] function. ... .
Using selectedOptions property. ... .
Using querySelectorAll[] method..

Chủ Đề