I have a form on my page with a bunch of inputs and some hidden fields, I\'ve been asked to pass this data through a \"post array\" only im unsure on how to do this,
<Give each input a name in array format:
<input type="hidden" name="data[EstPriceInput]" value="" />
Then the in PHP $_POST['data'];
will be an array:
print_r($_POST); // print out the whole post
print_r($_POST['data']); // print out only the data array
If you want everything in your post to be as $Variables you can use something like this:
foreach($_POST as $key => $value) {
eval("$" . $key . " = " . $value");
}
When you post that data, it is stored as an array in $_POST
.
You could optionally do something like:
<input name="arrayname[item1]">
<input name="arrayname[item2]">
<input name="arrayname[item3]">
Then:
$item1 = $_POST['arrayname']['item1'];
$item2 = $_POST['arrayname']['item2'];
$item3 = $_POST['arrayname']['item3'];
But I fail to see the point.
You're already doing that, as a matter of fact. When the form is submitted, the data is passed through a post array ($_POST). Your process.php is receiving that array and redistributing its values as individual variables.
What you are doing is not necessarily bad practice but it does however require an extraordinary amount of typing. I would accomplish what you are trying to do like this.
foreach($_POST as $var => $val){
$$var = $val;
}
This will take all the POST variables and put them in their own individual variables. So if you have a input field named email and the luser puts in Someone@example.com you will have a var named $email with a value of "Someone@example.com".
You can use the built-in function:
extract($_POST);
it will create a variable for each entry in $_POST
.