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

Git Tag Cheat Sheet

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

2 months ago

Understanding Web Storage: Cookies, Local Storage

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

3 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.…

3 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…

3 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…

5 months ago

How To Secure Nginx with Let’s Encrypt on Ubuntu EC2 Instance

Introduction Let's Encrypt is a Certificate Authority (CA) that makes it simple to obtain and…

7 months ago