gpt-3.5-turbo-0301· openai
Suzhen/CodeChat
how form submit with post method to pass an array with the form data?
- User
how form submit with post method to pass an array with the form data?
- Assistant
To pass an array with the form data using the POST method, you can follow these steps:
- Create a form element with the action and method attributes set to the target PHP script and "POST" respectively.
<form action="your-php-script.php" method="POST">- Create an input element with the name attribute set to the array name.
<input type="text" name="my_array[]" />Note the square brackets after the array name. This indicates that the input will be part of an array.
- Add as many input elements as necessary, each with the same array name.
<input type="text" name="my_array[]" /> <input type="text" name="my_array[]" /> <input type="text" name="my_array[]" />- Submit the form. In the target PHP script, use the $_POST superglobal to access the array values.
$myArray = $_POST["my_array"];You can then process the array values like any other PHP array.