Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$_POST Array from html form

Tags:

I am trying to send data from multiple checkboxes (id[]) and create an array "info" in php to allow me to run a script for each value (however the quantity of values may change each time) however first I am trying to display the content of each array value. I am not quite sure how to put my array populating line to save all the content to the array.

HTML

echo("<input name='id[]' type='checkbox' value='".$shopnumb."'>"); 

my hopeful processing code currently is -

$info=$_POST['id[]']; Echo(array_values($info)); 

what do I need to do to make the content sent by post from the form checkboxes populate the array info

any help is greatly appreciated

edited for clarification.

like image 994
James Stafford Avatar asked Jul 26 '12 18:07

James Stafford


People also ask

How can we send arrays in HTML forms?

You can create arrays in form fields using square brackets. That means you can name fields like account[first_name] and account[last_name] and in most server-side languages, you will end up with an 'account' array.

Is $_ post an array?

The PHP built-in variable $_POST is also an array and it holds the data that we provide along with the post method.

Can you post an array PHP?

Use the POST Method to Send an Array From a Form in PHP. We use the POST method to send data from a form in PHP. The POST method is an HTTP request method that creates or adds resources to the server. We use it when we have to send sensitive information like passwords.


1 Answers

Change

$info=$_POST['id[]']; 

to

$info=$_POST['id']; 

by adding [] to the end of your form field names, PHP will automatically convert these variables into arrays.

like image 130
Ross Smith II Avatar answered Sep 28 '22 01:09

Ross Smith II