Categories: PHP & Frameworks

PHP use of array in form ?

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>

Developer Diary

Share
Published by
Developer Diary

Recent Posts

Discover the Ultimate Tool for Frontend Designers and Developers

Introduction Even experienced developers may find it difficult to create aesthetically pleasing and useful web…

1 day ago

Git Tag Cheat Sheet

Introduction Git tags are an essential feature of version control systems, offering a simple way…

4 months ago

Understanding Web Storage: Cookies, Local Storage

Introduction The methods that browsers employ to store data on a user's device are referred…

5 months ago

Setting up OpenVPN Access Server in Amazon VPC – AWS

Introduction A well-known open-source VPN technology, OpenVPN provides strong protection for both people and businesses.…

5 months ago

Enhance Error Tracking & Monitoring: Integrate Sentry with Node.js & Express.js

Introduction Integrating Sentry into a Node.js, Express.js, and MongoDB backend project significantly enhances error tracking…

5 months ago

Comparing Callbacks, Promises, and Async/Await in JavaScript

Introduction In the world of JavaScript development, efficiently managing asynchronous operations is essential. Asynchronous programming…

7 months ago