PHP use of array in form ?

By November 4, 2011 PHP

Here is a simple example how to use array in html form element to store multiple value under single name.
<html>
<head>
<title>Use of array in form</title>
</head>
<body>
<h1>Use of array in form</h1>
<?php
if(isset($_REQUEST['artists'])){
?>

your favourite artists:
<?php
echo implode($_REQUEST['artists']," , ");
}
else
{
?>

<form method="post">
Select your favourite artists: <br />
<select name="artists[]" multiple="true">
<option value="Amitabh Bachan">Amitabh Bachan</option>
<option value="Shahrukh Khan">Shahrukh Khan</option>
<option value="Aamir Khan">Aamir Khan</option>
<option value="Salman Khan">Salman Khan</option>
<option value="Ajay Devgan">Ajay Devgan</option>
</select<
<input type="submit" name="submit" value="Submit" />
</form>

<?php
}
?>

</body>

</html>

Leave a Reply

61 − 57 =