Posting array from form
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,
Heres a snippet of what im doing at the moment
<form enctype="multipart/form-data" action="process.php" method="POST">
...
more inputs
...
<!-- Hidden data -->
<input type="hidden" name="TimeToRenderHoursInput" value="<?php echo $RenderHours; ?>" />
<input type="hidden" name="TimeToRenderDaysInput" value="<?php echo $RenderDays; ?>" />
<input type="hidden" name="TimeToRenderYearsInput" value="<?php echo $RenderYears; ?>" />
<input type="hidden" name="ContentMinutesInput" value="<?php echo $ContentMinutes; ?>" />
<input type="hidden" name="ContentMinutesSelector" value="<?php echo $ContentMinutesSelector; ?>" />
<input type="hidden" name="PriorityInput" value="<?php echo $Priority; ?>" />
<input type="hidden" name="AvgFrameRenderTimeInput" value="<?php echo $AverageFrameRenderTime; ?>" />
<input type="hidden" name="AvgFrameRenderTimeSelector" value="<?php echo $AverageFrameRenderSelector; ?>" />
<input type="hidden" name="CoresInTestInput" value="<?php echo $CoresInTest; ?>" />
<input type="hidden" name="EstPriceInput" value="<?php echo $EstPrice; ?>" />
<!-- End hidden -->
<input type="image" src="http://www.venndigital.co.uk/testsite/renderbutton/_includes/images/button/submit.jpg" alt="Submit" value="Submit" style="border:0!important;" />
In my process.php im then calling the data as such...
$first_name = $_POST['first_name'];
$company_name = $_POST['company_name'];
$email_from = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$RenderHours = $_POST['TimeToRenderHoursInput'];
$RenderDays = $_POST['TimeToRenderDaysInput'];
$RenderYears = $_POST['TimeToRenderYearsInput'];
$ContentMinutes = $_POST['ContentMinutesInput'];
$ContentMinutesSelector = $_POST['ContentMinutesSelector'];
$Priority = $_POST['PriorityInput'];
$AverageFrameRenderTime = $_POST['AvgFrameRenderTimeInput'];
$AverageFrameRenderSelector = $_POST['AvgFrameRenderTimeSelector'];
$CoresInTest = $_POST['CoresInTestInput'];
$EstPrice = $_POST['EstPriceInput'];
Is there a way to post it as an array? Is my method bad practice in anyway?
php html arrays post
add a comment |
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,
Heres a snippet of what im doing at the moment
<form enctype="multipart/form-data" action="process.php" method="POST">
...
more inputs
...
<!-- Hidden data -->
<input type="hidden" name="TimeToRenderHoursInput" value="<?php echo $RenderHours; ?>" />
<input type="hidden" name="TimeToRenderDaysInput" value="<?php echo $RenderDays; ?>" />
<input type="hidden" name="TimeToRenderYearsInput" value="<?php echo $RenderYears; ?>" />
<input type="hidden" name="ContentMinutesInput" value="<?php echo $ContentMinutes; ?>" />
<input type="hidden" name="ContentMinutesSelector" value="<?php echo $ContentMinutesSelector; ?>" />
<input type="hidden" name="PriorityInput" value="<?php echo $Priority; ?>" />
<input type="hidden" name="AvgFrameRenderTimeInput" value="<?php echo $AverageFrameRenderTime; ?>" />
<input type="hidden" name="AvgFrameRenderTimeSelector" value="<?php echo $AverageFrameRenderSelector; ?>" />
<input type="hidden" name="CoresInTestInput" value="<?php echo $CoresInTest; ?>" />
<input type="hidden" name="EstPriceInput" value="<?php echo $EstPrice; ?>" />
<!-- End hidden -->
<input type="image" src="http://www.venndigital.co.uk/testsite/renderbutton/_includes/images/button/submit.jpg" alt="Submit" value="Submit" style="border:0!important;" />
In my process.php im then calling the data as such...
$first_name = $_POST['first_name'];
$company_name = $_POST['company_name'];
$email_from = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$RenderHours = $_POST['TimeToRenderHoursInput'];
$RenderDays = $_POST['TimeToRenderDaysInput'];
$RenderYears = $_POST['TimeToRenderYearsInput'];
$ContentMinutes = $_POST['ContentMinutesInput'];
$ContentMinutesSelector = $_POST['ContentMinutesSelector'];
$Priority = $_POST['PriorityInput'];
$AverageFrameRenderTime = $_POST['AvgFrameRenderTimeInput'];
$AverageFrameRenderSelector = $_POST['AvgFrameRenderTimeSelector'];
$CoresInTest = $_POST['CoresInTestInput'];
$EstPrice = $_POST['EstPriceInput'];
Is there a way to post it as an array? Is my method bad practice in anyway?
php html arrays post
add a comment |
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,
Heres a snippet of what im doing at the moment
<form enctype="multipart/form-data" action="process.php" method="POST">
...
more inputs
...
<!-- Hidden data -->
<input type="hidden" name="TimeToRenderHoursInput" value="<?php echo $RenderHours; ?>" />
<input type="hidden" name="TimeToRenderDaysInput" value="<?php echo $RenderDays; ?>" />
<input type="hidden" name="TimeToRenderYearsInput" value="<?php echo $RenderYears; ?>" />
<input type="hidden" name="ContentMinutesInput" value="<?php echo $ContentMinutes; ?>" />
<input type="hidden" name="ContentMinutesSelector" value="<?php echo $ContentMinutesSelector; ?>" />
<input type="hidden" name="PriorityInput" value="<?php echo $Priority; ?>" />
<input type="hidden" name="AvgFrameRenderTimeInput" value="<?php echo $AverageFrameRenderTime; ?>" />
<input type="hidden" name="AvgFrameRenderTimeSelector" value="<?php echo $AverageFrameRenderSelector; ?>" />
<input type="hidden" name="CoresInTestInput" value="<?php echo $CoresInTest; ?>" />
<input type="hidden" name="EstPriceInput" value="<?php echo $EstPrice; ?>" />
<!-- End hidden -->
<input type="image" src="http://www.venndigital.co.uk/testsite/renderbutton/_includes/images/button/submit.jpg" alt="Submit" value="Submit" style="border:0!important;" />
In my process.php im then calling the data as such...
$first_name = $_POST['first_name'];
$company_name = $_POST['company_name'];
$email_from = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$RenderHours = $_POST['TimeToRenderHoursInput'];
$RenderDays = $_POST['TimeToRenderDaysInput'];
$RenderYears = $_POST['TimeToRenderYearsInput'];
$ContentMinutes = $_POST['ContentMinutesInput'];
$ContentMinutesSelector = $_POST['ContentMinutesSelector'];
$Priority = $_POST['PriorityInput'];
$AverageFrameRenderTime = $_POST['AvgFrameRenderTimeInput'];
$AverageFrameRenderSelector = $_POST['AvgFrameRenderTimeSelector'];
$CoresInTest = $_POST['CoresInTestInput'];
$EstPrice = $_POST['EstPriceInput'];
Is there a way to post it as an array? Is my method bad practice in anyway?
php html arrays post
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,
Heres a snippet of what im doing at the moment
<form enctype="multipart/form-data" action="process.php" method="POST">
...
more inputs
...
<!-- Hidden data -->
<input type="hidden" name="TimeToRenderHoursInput" value="<?php echo $RenderHours; ?>" />
<input type="hidden" name="TimeToRenderDaysInput" value="<?php echo $RenderDays; ?>" />
<input type="hidden" name="TimeToRenderYearsInput" value="<?php echo $RenderYears; ?>" />
<input type="hidden" name="ContentMinutesInput" value="<?php echo $ContentMinutes; ?>" />
<input type="hidden" name="ContentMinutesSelector" value="<?php echo $ContentMinutesSelector; ?>" />
<input type="hidden" name="PriorityInput" value="<?php echo $Priority; ?>" />
<input type="hidden" name="AvgFrameRenderTimeInput" value="<?php echo $AverageFrameRenderTime; ?>" />
<input type="hidden" name="AvgFrameRenderTimeSelector" value="<?php echo $AverageFrameRenderSelector; ?>" />
<input type="hidden" name="CoresInTestInput" value="<?php echo $CoresInTest; ?>" />
<input type="hidden" name="EstPriceInput" value="<?php echo $EstPrice; ?>" />
<!-- End hidden -->
<input type="image" src="http://www.venndigital.co.uk/testsite/renderbutton/_includes/images/button/submit.jpg" alt="Submit" value="Submit" style="border:0!important;" />
In my process.php im then calling the data as such...
$first_name = $_POST['first_name'];
$company_name = $_POST['company_name'];
$email_from = $_POST['email'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$RenderHours = $_POST['TimeToRenderHoursInput'];
$RenderDays = $_POST['TimeToRenderDaysInput'];
$RenderYears = $_POST['TimeToRenderYearsInput'];
$ContentMinutes = $_POST['ContentMinutesInput'];
$ContentMinutesSelector = $_POST['ContentMinutesSelector'];
$Priority = $_POST['PriorityInput'];
$AverageFrameRenderTime = $_POST['AvgFrameRenderTimeInput'];
$AverageFrameRenderSelector = $_POST['AvgFrameRenderTimeSelector'];
$CoresInTest = $_POST['CoresInTestInput'];
$EstPrice = $_POST['EstPriceInput'];
Is there a way to post it as an array? Is my method bad practice in anyway?
php html arrays post
php html arrays post
asked May 27 '11 at 12:47
Liam
3,8962786178
3,8962786178
add a comment |
add a comment |
7 Answers
7
active
oldest
votes
give each input a name like
<input type="hidden" name="data[EstPriceInput]" value="" />
then the in php
$_POST['data'];
print_r($_POST);//print out the whole post
print_r($_POST['data']); //print out only the data array
will be an array
2
will this be a good practice? one thing I saw an importance of this is when you want to insert the values in the database without typing all the fields, you'll just loop through the array?
– mmr
Dec 2 '14 at 7:27
add a comment |
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]">
and
$item1 = $_POST['arrayname']['item1'];
$item2 = $_POST['arrayname']['item2'];
$item3 = $_POST['arrayname']['item3'];
but i fail to see the point. maybe get more clarification?
I've been asked to build an order form page for a client and they want the data passing to them in a POST array, as im no php developer I was wondering if my way posted above would suffice or if its frowned upon in any way?
– Liam
May 27 '11 at 12:53
1
There is nothing wrong with the code you posted. If there are only certain hidden form elements they want in this array (and not the rest of the form) then I can see wanting a multidimensional array. This would be accomplished by using the above code. But yeah, nothing wrong with your code.
– David Houde
May 27 '11 at 12:57
add a comment |
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.
it may in fact be an array but that array also has other data in it that the he may not want to sift through
– mcgrailm
May 27 '11 at 12:59
Ahh, Is there a way it can be printed out an array then? I've tried using <?php print_r(); ?> only it doesnt print anything out, I have to use my above code, if this makes sense?
– Liam
May 27 '11 at 12:59
add a comment |
Why are you sending it through a post if you already have it on the server (PHP) side?
Why not just save the array to the $_SESSION
variable so you can use it when the form gets submitted, that might make it more "secure" since then the client cannot change the variables by editing the source.
It will depend upon how you really want to do.
add a comment |
You can use the built-in function:
extract($_POST);
it will create a variable for each entry in $_POST
.
add a comment |
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".
5
Thats bad design. Really, really, really bad design. 1) "var" can be user submitted 2) val can be user submitted. So someone could send existing app variables to the script and this would override it!
– przemo_li
Jul 28 '14 at 7:54
add a comment |
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");
}
Might be not fully correct
– Guus Geurkink
May 27 '11 at 13:18
5
eval is evil don't use it
– mcgrailm
May 27 '11 at 16:28
4
Security risk. (When $key is equal to already existing variables in the script)
– przemo_li
Jul 28 '14 at 7:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6152436%2fposting-array-from-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
give each input a name like
<input type="hidden" name="data[EstPriceInput]" value="" />
then the in php
$_POST['data'];
print_r($_POST);//print out the whole post
print_r($_POST['data']); //print out only the data array
will be an array
2
will this be a good practice? one thing I saw an importance of this is when you want to insert the values in the database without typing all the fields, you'll just loop through the array?
– mmr
Dec 2 '14 at 7:27
add a comment |
give each input a name like
<input type="hidden" name="data[EstPriceInput]" value="" />
then the in php
$_POST['data'];
print_r($_POST);//print out the whole post
print_r($_POST['data']); //print out only the data array
will be an array
2
will this be a good practice? one thing I saw an importance of this is when you want to insert the values in the database without typing all the fields, you'll just loop through the array?
– mmr
Dec 2 '14 at 7:27
add a comment |
give each input a name like
<input type="hidden" name="data[EstPriceInput]" value="" />
then the in php
$_POST['data'];
print_r($_POST);//print out the whole post
print_r($_POST['data']); //print out only the data array
will be an array
give each input a name like
<input type="hidden" name="data[EstPriceInput]" value="" />
then the in php
$_POST['data'];
print_r($_POST);//print out the whole post
print_r($_POST['data']); //print out only the data array
will be an array
edited Sep 12 '12 at 17:32
jay
8,10752950
8,10752950
answered May 27 '11 at 12:50
mcgrailm
13k2067122
13k2067122
2
will this be a good practice? one thing I saw an importance of this is when you want to insert the values in the database without typing all the fields, you'll just loop through the array?
– mmr
Dec 2 '14 at 7:27
add a comment |
2
will this be a good practice? one thing I saw an importance of this is when you want to insert the values in the database without typing all the fields, you'll just loop through the array?
– mmr
Dec 2 '14 at 7:27
2
2
will this be a good practice? one thing I saw an importance of this is when you want to insert the values in the database without typing all the fields, you'll just loop through the array?
– mmr
Dec 2 '14 at 7:27
will this be a good practice? one thing I saw an importance of this is when you want to insert the values in the database without typing all the fields, you'll just loop through the array?
– mmr
Dec 2 '14 at 7:27
add a comment |
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]">
and
$item1 = $_POST['arrayname']['item1'];
$item2 = $_POST['arrayname']['item2'];
$item3 = $_POST['arrayname']['item3'];
but i fail to see the point. maybe get more clarification?
I've been asked to build an order form page for a client and they want the data passing to them in a POST array, as im no php developer I was wondering if my way posted above would suffice or if its frowned upon in any way?
– Liam
May 27 '11 at 12:53
1
There is nothing wrong with the code you posted. If there are only certain hidden form elements they want in this array (and not the rest of the form) then I can see wanting a multidimensional array. This would be accomplished by using the above code. But yeah, nothing wrong with your code.
– David Houde
May 27 '11 at 12:57
add a comment |
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]">
and
$item1 = $_POST['arrayname']['item1'];
$item2 = $_POST['arrayname']['item2'];
$item3 = $_POST['arrayname']['item3'];
but i fail to see the point. maybe get more clarification?
I've been asked to build an order form page for a client and they want the data passing to them in a POST array, as im no php developer I was wondering if my way posted above would suffice or if its frowned upon in any way?
– Liam
May 27 '11 at 12:53
1
There is nothing wrong with the code you posted. If there are only certain hidden form elements they want in this array (and not the rest of the form) then I can see wanting a multidimensional array. This would be accomplished by using the above code. But yeah, nothing wrong with your code.
– David Houde
May 27 '11 at 12:57
add a comment |
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]">
and
$item1 = $_POST['arrayname']['item1'];
$item2 = $_POST['arrayname']['item2'];
$item3 = $_POST['arrayname']['item3'];
but i fail to see the point. maybe get more clarification?
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]">
and
$item1 = $_POST['arrayname']['item1'];
$item2 = $_POST['arrayname']['item2'];
$item3 = $_POST['arrayname']['item3'];
but i fail to see the point. maybe get more clarification?
answered May 27 '11 at 12:50
David Houde
4,48411226
4,48411226
I've been asked to build an order form page for a client and they want the data passing to them in a POST array, as im no php developer I was wondering if my way posted above would suffice or if its frowned upon in any way?
– Liam
May 27 '11 at 12:53
1
There is nothing wrong with the code you posted. If there are only certain hidden form elements they want in this array (and not the rest of the form) then I can see wanting a multidimensional array. This would be accomplished by using the above code. But yeah, nothing wrong with your code.
– David Houde
May 27 '11 at 12:57
add a comment |
I've been asked to build an order form page for a client and they want the data passing to them in a POST array, as im no php developer I was wondering if my way posted above would suffice or if its frowned upon in any way?
– Liam
May 27 '11 at 12:53
1
There is nothing wrong with the code you posted. If there are only certain hidden form elements they want in this array (and not the rest of the form) then I can see wanting a multidimensional array. This would be accomplished by using the above code. But yeah, nothing wrong with your code.
– David Houde
May 27 '11 at 12:57
I've been asked to build an order form page for a client and they want the data passing to them in a POST array, as im no php developer I was wondering if my way posted above would suffice or if its frowned upon in any way?
– Liam
May 27 '11 at 12:53
I've been asked to build an order form page for a client and they want the data passing to them in a POST array, as im no php developer I was wondering if my way posted above would suffice or if its frowned upon in any way?
– Liam
May 27 '11 at 12:53
1
1
There is nothing wrong with the code you posted. If there are only certain hidden form elements they want in this array (and not the rest of the form) then I can see wanting a multidimensional array. This would be accomplished by using the above code. But yeah, nothing wrong with your code.
– David Houde
May 27 '11 at 12:57
There is nothing wrong with the code you posted. If there are only certain hidden form elements they want in this array (and not the rest of the form) then I can see wanting a multidimensional array. This would be accomplished by using the above code. But yeah, nothing wrong with your code.
– David Houde
May 27 '11 at 12:57
add a comment |
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.
it may in fact be an array but that array also has other data in it that the he may not want to sift through
– mcgrailm
May 27 '11 at 12:59
Ahh, Is there a way it can be printed out an array then? I've tried using <?php print_r(); ?> only it doesnt print anything out, I have to use my above code, if this makes sense?
– Liam
May 27 '11 at 12:59
add a comment |
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.
it may in fact be an array but that array also has other data in it that the he may not want to sift through
– mcgrailm
May 27 '11 at 12:59
Ahh, Is there a way it can be printed out an array then? I've tried using <?php print_r(); ?> only it doesnt print anything out, I have to use my above code, if this makes sense?
– Liam
May 27 '11 at 12:59
add a comment |
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.
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.
answered May 27 '11 at 12:52
Allen
68057
68057
it may in fact be an array but that array also has other data in it that the he may not want to sift through
– mcgrailm
May 27 '11 at 12:59
Ahh, Is there a way it can be printed out an array then? I've tried using <?php print_r(); ?> only it doesnt print anything out, I have to use my above code, if this makes sense?
– Liam
May 27 '11 at 12:59
add a comment |
it may in fact be an array but that array also has other data in it that the he may not want to sift through
– mcgrailm
May 27 '11 at 12:59
Ahh, Is there a way it can be printed out an array then? I've tried using <?php print_r(); ?> only it doesnt print anything out, I have to use my above code, if this makes sense?
– Liam
May 27 '11 at 12:59
it may in fact be an array but that array also has other data in it that the he may not want to sift through
– mcgrailm
May 27 '11 at 12:59
it may in fact be an array but that array also has other data in it that the he may not want to sift through
– mcgrailm
May 27 '11 at 12:59
Ahh, Is there a way it can be printed out an array then? I've tried using <?php print_r(); ?> only it doesnt print anything out, I have to use my above code, if this makes sense?
– Liam
May 27 '11 at 12:59
Ahh, Is there a way it can be printed out an array then? I've tried using <?php print_r(); ?> only it doesnt print anything out, I have to use my above code, if this makes sense?
– Liam
May 27 '11 at 12:59
add a comment |
Why are you sending it through a post if you already have it on the server (PHP) side?
Why not just save the array to the $_SESSION
variable so you can use it when the form gets submitted, that might make it more "secure" since then the client cannot change the variables by editing the source.
It will depend upon how you really want to do.
add a comment |
Why are you sending it through a post if you already have it on the server (PHP) side?
Why not just save the array to the $_SESSION
variable so you can use it when the form gets submitted, that might make it more "secure" since then the client cannot change the variables by editing the source.
It will depend upon how you really want to do.
add a comment |
Why are you sending it through a post if you already have it on the server (PHP) side?
Why not just save the array to the $_SESSION
variable so you can use it when the form gets submitted, that might make it more "secure" since then the client cannot change the variables by editing the source.
It will depend upon how you really want to do.
Why are you sending it through a post if you already have it on the server (PHP) side?
Why not just save the array to the $_SESSION
variable so you can use it when the form gets submitted, that might make it more "secure" since then the client cannot change the variables by editing the source.
It will depend upon how you really want to do.
edited Mar 20 '14 at 11:53
answered Feb 27 '14 at 8:37
Nagama Inamdar
2,28962642
2,28962642
add a comment |
add a comment |
You can use the built-in function:
extract($_POST);
it will create a variable for each entry in $_POST
.
add a comment |
You can use the built-in function:
extract($_POST);
it will create a variable for each entry in $_POST
.
add a comment |
You can use the built-in function:
extract($_POST);
it will create a variable for each entry in $_POST
.
You can use the built-in function:
extract($_POST);
it will create a variable for each entry in $_POST
.
edited Mar 17 at 4:53
Stephen Rauch
27.7k153256
27.7k153256
answered Mar 17 at 4:31
Manunich
12
12
add a comment |
add a comment |
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".
5
Thats bad design. Really, really, really bad design. 1) "var" can be user submitted 2) val can be user submitted. So someone could send existing app variables to the script and this would override it!
– przemo_li
Jul 28 '14 at 7:54
add a comment |
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".
5
Thats bad design. Really, really, really bad design. 1) "var" can be user submitted 2) val can be user submitted. So someone could send existing app variables to the script and this would override it!
– przemo_li
Jul 28 '14 at 7:54
add a comment |
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".
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".
answered Nov 10 '13 at 2:54
user2558999
193
193
5
Thats bad design. Really, really, really bad design. 1) "var" can be user submitted 2) val can be user submitted. So someone could send existing app variables to the script and this would override it!
– przemo_li
Jul 28 '14 at 7:54
add a comment |
5
Thats bad design. Really, really, really bad design. 1) "var" can be user submitted 2) val can be user submitted. So someone could send existing app variables to the script and this would override it!
– przemo_li
Jul 28 '14 at 7:54
5
5
Thats bad design. Really, really, really bad design. 1) "var" can be user submitted 2) val can be user submitted. So someone could send existing app variables to the script and this would override it!
– przemo_li
Jul 28 '14 at 7:54
Thats bad design. Really, really, really bad design. 1) "var" can be user submitted 2) val can be user submitted. So someone could send existing app variables to the script and this would override it!
– przemo_li
Jul 28 '14 at 7:54
add a comment |
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");
}
Might be not fully correct
– Guus Geurkink
May 27 '11 at 13:18
5
eval is evil don't use it
– mcgrailm
May 27 '11 at 16:28
4
Security risk. (When $key is equal to already existing variables in the script)
– przemo_li
Jul 28 '14 at 7:56
add a comment |
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");
}
Might be not fully correct
– Guus Geurkink
May 27 '11 at 13:18
5
eval is evil don't use it
– mcgrailm
May 27 '11 at 16:28
4
Security risk. (When $key is equal to already existing variables in the script)
– przemo_li
Jul 28 '14 at 7:56
add a comment |
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");
}
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");
}
answered May 27 '11 at 13:18
Guus Geurkink
1712211
1712211
Might be not fully correct
– Guus Geurkink
May 27 '11 at 13:18
5
eval is evil don't use it
– mcgrailm
May 27 '11 at 16:28
4
Security risk. (When $key is equal to already existing variables in the script)
– przemo_li
Jul 28 '14 at 7:56
add a comment |
Might be not fully correct
– Guus Geurkink
May 27 '11 at 13:18
5
eval is evil don't use it
– mcgrailm
May 27 '11 at 16:28
4
Security risk. (When $key is equal to already existing variables in the script)
– przemo_li
Jul 28 '14 at 7:56
Might be not fully correct
– Guus Geurkink
May 27 '11 at 13:18
Might be not fully correct
– Guus Geurkink
May 27 '11 at 13:18
5
5
eval is evil don't use it
– mcgrailm
May 27 '11 at 16:28
eval is evil don't use it
– mcgrailm
May 27 '11 at 16:28
4
4
Security risk. (When $key is equal to already existing variables in the script)
– przemo_li
Jul 28 '14 at 7:56
Security risk. (When $key is equal to already existing variables in the script)
– przemo_li
Jul 28 '14 at 7:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f6152436%2fposting-array-from-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown