Link to home
Start Free TrialLog in
Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on

Multi-select select list - process in php

If you have a form with a select element with multiple selections allowed, how do you process the selections in the php form processing program?

If the form element is called "choices", in the php program how to I separate out the individual choices made?

Thanks
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Please post the form so we can show you a tested-and-working code example, thanks.  

In the action script you can learn about what the form sends by using var_dump($_REQUEST)
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A 'GET' version works as well.  Save this one as 'multiselectget.php'.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<title>Multi-select select list in php</title>
</head>
<body>
<h1>Multi-select select list in php</h1>

<form action="" method="post" enctype="multipart/form-data">

<select name="sometext[]" id="sometext" multiple="multiple">
<option value="1">text1</option>
<option value="2">text2</option>
<option value="3">text3</option>
<option value="4">text4</option>
<option value="5">text5</option>
<option value="6">text6</option>
</select>
<input type="submit" name="submit" value="Submit" />
</form>
<pre>

<?php 
if(isset($_REQUEST['submit'])) {
	echo "<b>GET</b><br>";
	var_dump($_GET);
	echo "<br><b>POST</b><br>";
	var_dump($_POST);
	echo "<br><b>REQUEST</b><br>";
	var_dump($_REQUEST);
	}
?>

</pre>
<br /> 
<a href="multiselectget.php">multiselectget.php</a>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial