I have this form
<form action = "put the data to a single PHP array" method="post">
<input name="a" type="text" />
<input name="b" type="text" />
<input name="c" type="text" />
<input name="d" type="text" />
<input type="button">
</form>
the condition is that I want to put the data into a PHP array when the user filled the form and click the submit button. the data should be order the way the text input fields are arranged. how can I do that?
Pls help me with the code. thanks!
Change the name of your inputs like this:
<form action = "put the data to a single PHP array" method="post">
<input name="a[]" type="text" />
<input name="a[]" type="text" />
<input name="a[]" type="text" />
<input name="a[]" type="text" />
<input type="button"/>
</form>
You can then retrieve the array as follows:
$values = $_POST['a'];
hi Jonas if you need the values to be passed as an array then you can use
<form action = "submit the data to a PHP array" method="post">
<input name="ar[]" type="text" />
<input name="ar[]" type="text" />
<input name="ar[]" type="text" />
<input name="ar[]" type="text" />
<input type="button">
</form>
while accessing you can use
$ar=$_POST['ar'];
$size=sizeof($ar);
for($i=0;$i<$size;$i++)
{
echo "$ar[$i]";
}
Generally we use this type of array passing when we use multiple checkboxes value to be passed