Passing Array Using Html Form Hidden Element
I am trying to post an array in a hidden field and want to retrieve that array after submitting form in php.
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
But getting only array string after printting the posted value.
So how can i solve it?
php
add a comment |
I am trying to post an array in a hidden field and want to retrieve that array after submitting form in php.
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
But getting only array string after printting the posted value.
So how can i solve it?
php
1
You need to serialize it in some way. Check out the serialize and json_encode functions. I'd recommend going with the json_encode.
– Gazler
Jul 1 '11 at 11:14
add a comment |
I am trying to post an array in a hidden field and want to retrieve that array after submitting form in php.
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
But getting only array string after printting the posted value.
So how can i solve it?
php
I am trying to post an array in a hidden field and want to retrieve that array after submitting form in php.
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
But getting only array string after printting the posted value.
So how can i solve it?
php
php
asked Jul 1 '11 at 11:13
ShrishailShrishail
423147
423147
1
You need to serialize it in some way. Check out the serialize and json_encode functions. I'd recommend going with the json_encode.
– Gazler
Jul 1 '11 at 11:14
add a comment |
1
You need to serialize it in some way. Check out the serialize and json_encode functions. I'd recommend going with the json_encode.
– Gazler
Jul 1 '11 at 11:14
1
1
You need to serialize it in some way. Check out the serialize and json_encode functions. I'd recommend going with the json_encode.
– Gazler
Jul 1 '11 at 11:14
You need to serialize it in some way. Check out the serialize and json_encode functions. I'd recommend going with the json_encode.
– Gazler
Jul 1 '11 at 11:14
add a comment |
8 Answers
8
active
oldest
votes
$postvalue=array("a","b","c");
foreach($postvalue as $value)
{
echo '<input type="hidden" name="result" value="'. $value. '">';
}
and you will got $_POST['result']
as array
print_r($_POST['result']);
this solution is very helpful for me thanks
– Sourabh Sharma
Oct 13 '18 at 16:04
add a comment |
There are mainly two possible ways to achieve this:
Serialize the data in some way:
$postvalue = serialize($array); // client side
$array = unserialize($_POST['result']; //server side
And then you can unserialize the posted values with
unserialize($postvalue)
Further information on this is here in the php manuals.
Alternativley you can use the
json_encode()
andjson_decode()
functions to get a json formatted serialized string. You could even shrink the transmitted data withgzcompress()
(note that this is performance intensive) and secure the transmitted data withbase64_encode()
(to make your data survive in non-8bit clean transport layers) This could look like this:
$postvalue = base64_encode(json_encode($array)); //client side
$array = json_decode(base64_decode($_POST['result'])); //server side
A not recommended way to serialize your data (but very cheap in performance) is to simply use
implode()
on your array to get a string with all values separated by some specified character. On serverside you can retrieve the array withexplode()
then. But note that you shouldn't use a character for separation that occurs in the array values (or then escape it) and that you cannot transmit the array keys with this method.
Use the properties of special named input elements:
$postvalue = "";
foreach ($array as $v) {
$postvalue .= '<input type="hidden" name="result" value="' .$v. '" />';
}
Like this you get your entire array in the
$_POST['result']
variable if the form is sent. Note that this doesn't transmit array keys. However you can achieve this by usingresult[$key]
as name of each field.
Every of this methods got their own advantages and disadvantages. What you use is mainly depending on how large your array will be, since you should try to send a minimal amount of data with all of this methods.
An other way to achieve the same is to store the array in a server side session instead of transmitting it client side. Like this you can access the array over the $_SESSION
variable and don't have to transmit anything over the form. For this have a look at a basic usage example of sessions on php.net
I had to use single quotes aroundvalue
attribute. Otherwise the data was being trimmed at the first double quote in the serialized version.
– VeeK
Sep 23 '17 at 10:29
I did this using json_encode. The second argument for json_decode had to be true in my case (to return associative array instead of StdClass as the default)
– jamil
Jan 4 '18 at 0:02
add a comment |
You can use serialize and base64_encode from client side,
After then use unserialize and base64_decode to server side
Like as:
In Client side use:
$postvalue=array("a","b","c");
$postvalue = base64_encode(serialize($array));
//your form hidden input
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
In Server side use:
$postvalue = unserialize(base64_decode($_POST['result']));
print_r($postvalue) //your desired array data will be printed here
This should be the correct answer, better than use foreach, you can pass objects into arrays, and multilevel arrays
– Leonardo Sapuy
Jun 23 '17 at 16:32
This answer doesn't get enough credit. Just using serialize() or json_encode() are things that most people have tried and realize fail on the basis of quotation marks by the time they get here. This answer takes it a step further and encodes it in a way that makes that issue irrelevant in an elegant manner. Bravo!
– Kaji
Oct 12 '17 at 6:28
I agree, this should be the correct answer
– barakadam
Jan 19 '18 at 21:29
add a comment |
Either serialize:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo serialize($postvalue); ?>">
on receive: unserialize($_POST['result'])
or implode:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo implode(',', $postvalue); ?>">
on receive: explode(',', $_POST['result'])
serialize can mess up your quotes or brackets and mix up with html.. I would use accepted answer
– zachu
May 8 '15 at 14:32
add a comment |
it's better to encode first to JSON-string and then encode with base64 eg. on server side in reverse order: use first base64_decode then json_decode functions. so you will restore your php array
add a comment |
If you want to post an array you must use another notation:
foreach ($postvalue as $value){
<input type="hidden" name="result" value="$value.">
}
in this way you have three input fields with the name result and when posted $_POST['result']
will be an array
add a comment |
<input type="hidden" name="item" value="[anyvalue]">
Let it be in a repeated mode it will post this element in the form as an array and use the
print_r($_POST['item'])
To retrieve the item
add a comment |
you can do it like this
<input type="hidden" name="result" value="<?php foreach($postvalue as $value) echo $postvalue.","; ?>">
5
Or just use implode ;-)
– Alex
Jul 1 '11 at 11:20
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%2f6547209%2fpassing-array-using-html-form-hidden-element%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
$postvalue=array("a","b","c");
foreach($postvalue as $value)
{
echo '<input type="hidden" name="result" value="'. $value. '">';
}
and you will got $_POST['result']
as array
print_r($_POST['result']);
this solution is very helpful for me thanks
– Sourabh Sharma
Oct 13 '18 at 16:04
add a comment |
$postvalue=array("a","b","c");
foreach($postvalue as $value)
{
echo '<input type="hidden" name="result" value="'. $value. '">';
}
and you will got $_POST['result']
as array
print_r($_POST['result']);
this solution is very helpful for me thanks
– Sourabh Sharma
Oct 13 '18 at 16:04
add a comment |
$postvalue=array("a","b","c");
foreach($postvalue as $value)
{
echo '<input type="hidden" name="result" value="'. $value. '">';
}
and you will got $_POST['result']
as array
print_r($_POST['result']);
$postvalue=array("a","b","c");
foreach($postvalue as $value)
{
echo '<input type="hidden" name="result" value="'. $value. '">';
}
and you will got $_POST['result']
as array
print_r($_POST['result']);
answered Jul 1 '11 at 11:15
Shakti SinghShakti Singh
65.2k16115141
65.2k16115141
this solution is very helpful for me thanks
– Sourabh Sharma
Oct 13 '18 at 16:04
add a comment |
this solution is very helpful for me thanks
– Sourabh Sharma
Oct 13 '18 at 16:04
this solution is very helpful for me thanks
– Sourabh Sharma
Oct 13 '18 at 16:04
this solution is very helpful for me thanks
– Sourabh Sharma
Oct 13 '18 at 16:04
add a comment |
There are mainly two possible ways to achieve this:
Serialize the data in some way:
$postvalue = serialize($array); // client side
$array = unserialize($_POST['result']; //server side
And then you can unserialize the posted values with
unserialize($postvalue)
Further information on this is here in the php manuals.
Alternativley you can use the
json_encode()
andjson_decode()
functions to get a json formatted serialized string. You could even shrink the transmitted data withgzcompress()
(note that this is performance intensive) and secure the transmitted data withbase64_encode()
(to make your data survive in non-8bit clean transport layers) This could look like this:
$postvalue = base64_encode(json_encode($array)); //client side
$array = json_decode(base64_decode($_POST['result'])); //server side
A not recommended way to serialize your data (but very cheap in performance) is to simply use
implode()
on your array to get a string with all values separated by some specified character. On serverside you can retrieve the array withexplode()
then. But note that you shouldn't use a character for separation that occurs in the array values (or then escape it) and that you cannot transmit the array keys with this method.
Use the properties of special named input elements:
$postvalue = "";
foreach ($array as $v) {
$postvalue .= '<input type="hidden" name="result" value="' .$v. '" />';
}
Like this you get your entire array in the
$_POST['result']
variable if the form is sent. Note that this doesn't transmit array keys. However you can achieve this by usingresult[$key]
as name of each field.
Every of this methods got their own advantages and disadvantages. What you use is mainly depending on how large your array will be, since you should try to send a minimal amount of data with all of this methods.
An other way to achieve the same is to store the array in a server side session instead of transmitting it client side. Like this you can access the array over the $_SESSION
variable and don't have to transmit anything over the form. For this have a look at a basic usage example of sessions on php.net
I had to use single quotes aroundvalue
attribute. Otherwise the data was being trimmed at the first double quote in the serialized version.
– VeeK
Sep 23 '17 at 10:29
I did this using json_encode. The second argument for json_decode had to be true in my case (to return associative array instead of StdClass as the default)
– jamil
Jan 4 '18 at 0:02
add a comment |
There are mainly two possible ways to achieve this:
Serialize the data in some way:
$postvalue = serialize($array); // client side
$array = unserialize($_POST['result']; //server side
And then you can unserialize the posted values with
unserialize($postvalue)
Further information on this is here in the php manuals.
Alternativley you can use the
json_encode()
andjson_decode()
functions to get a json formatted serialized string. You could even shrink the transmitted data withgzcompress()
(note that this is performance intensive) and secure the transmitted data withbase64_encode()
(to make your data survive in non-8bit clean transport layers) This could look like this:
$postvalue = base64_encode(json_encode($array)); //client side
$array = json_decode(base64_decode($_POST['result'])); //server side
A not recommended way to serialize your data (but very cheap in performance) is to simply use
implode()
on your array to get a string with all values separated by some specified character. On serverside you can retrieve the array withexplode()
then. But note that you shouldn't use a character for separation that occurs in the array values (or then escape it) and that you cannot transmit the array keys with this method.
Use the properties of special named input elements:
$postvalue = "";
foreach ($array as $v) {
$postvalue .= '<input type="hidden" name="result" value="' .$v. '" />';
}
Like this you get your entire array in the
$_POST['result']
variable if the form is sent. Note that this doesn't transmit array keys. However you can achieve this by usingresult[$key]
as name of each field.
Every of this methods got their own advantages and disadvantages. What you use is mainly depending on how large your array will be, since you should try to send a minimal amount of data with all of this methods.
An other way to achieve the same is to store the array in a server side session instead of transmitting it client side. Like this you can access the array over the $_SESSION
variable and don't have to transmit anything over the form. For this have a look at a basic usage example of sessions on php.net
I had to use single quotes aroundvalue
attribute. Otherwise the data was being trimmed at the first double quote in the serialized version.
– VeeK
Sep 23 '17 at 10:29
I did this using json_encode. The second argument for json_decode had to be true in my case (to return associative array instead of StdClass as the default)
– jamil
Jan 4 '18 at 0:02
add a comment |
There are mainly two possible ways to achieve this:
Serialize the data in some way:
$postvalue = serialize($array); // client side
$array = unserialize($_POST['result']; //server side
And then you can unserialize the posted values with
unserialize($postvalue)
Further information on this is here in the php manuals.
Alternativley you can use the
json_encode()
andjson_decode()
functions to get a json formatted serialized string. You could even shrink the transmitted data withgzcompress()
(note that this is performance intensive) and secure the transmitted data withbase64_encode()
(to make your data survive in non-8bit clean transport layers) This could look like this:
$postvalue = base64_encode(json_encode($array)); //client side
$array = json_decode(base64_decode($_POST['result'])); //server side
A not recommended way to serialize your data (but very cheap in performance) is to simply use
implode()
on your array to get a string with all values separated by some specified character. On serverside you can retrieve the array withexplode()
then. But note that you shouldn't use a character for separation that occurs in the array values (or then escape it) and that you cannot transmit the array keys with this method.
Use the properties of special named input elements:
$postvalue = "";
foreach ($array as $v) {
$postvalue .= '<input type="hidden" name="result" value="' .$v. '" />';
}
Like this you get your entire array in the
$_POST['result']
variable if the form is sent. Note that this doesn't transmit array keys. However you can achieve this by usingresult[$key]
as name of each field.
Every of this methods got their own advantages and disadvantages. What you use is mainly depending on how large your array will be, since you should try to send a minimal amount of data with all of this methods.
An other way to achieve the same is to store the array in a server side session instead of transmitting it client side. Like this you can access the array over the $_SESSION
variable and don't have to transmit anything over the form. For this have a look at a basic usage example of sessions on php.net
There are mainly two possible ways to achieve this:
Serialize the data in some way:
$postvalue = serialize($array); // client side
$array = unserialize($_POST['result']; //server side
And then you can unserialize the posted values with
unserialize($postvalue)
Further information on this is here in the php manuals.
Alternativley you can use the
json_encode()
andjson_decode()
functions to get a json formatted serialized string. You could even shrink the transmitted data withgzcompress()
(note that this is performance intensive) and secure the transmitted data withbase64_encode()
(to make your data survive in non-8bit clean transport layers) This could look like this:
$postvalue = base64_encode(json_encode($array)); //client side
$array = json_decode(base64_decode($_POST['result'])); //server side
A not recommended way to serialize your data (but very cheap in performance) is to simply use
implode()
on your array to get a string with all values separated by some specified character. On serverside you can retrieve the array withexplode()
then. But note that you shouldn't use a character for separation that occurs in the array values (or then escape it) and that you cannot transmit the array keys with this method.
Use the properties of special named input elements:
$postvalue = "";
foreach ($array as $v) {
$postvalue .= '<input type="hidden" name="result" value="' .$v. '" />';
}
Like this you get your entire array in the
$_POST['result']
variable if the form is sent. Note that this doesn't transmit array keys. However you can achieve this by usingresult[$key]
as name of each field.
Every of this methods got their own advantages and disadvantages. What you use is mainly depending on how large your array will be, since you should try to send a minimal amount of data with all of this methods.
An other way to achieve the same is to store the array in a server side session instead of transmitting it client side. Like this you can access the array over the $_SESSION
variable and don't have to transmit anything over the form. For this have a look at a basic usage example of sessions on php.net
edited Jun 10 '14 at 18:11
Plyto
5411818
5411818
answered Jul 1 '11 at 11:49
s1lences1lence
1,68621331
1,68621331
I had to use single quotes aroundvalue
attribute. Otherwise the data was being trimmed at the first double quote in the serialized version.
– VeeK
Sep 23 '17 at 10:29
I did this using json_encode. The second argument for json_decode had to be true in my case (to return associative array instead of StdClass as the default)
– jamil
Jan 4 '18 at 0:02
add a comment |
I had to use single quotes aroundvalue
attribute. Otherwise the data was being trimmed at the first double quote in the serialized version.
– VeeK
Sep 23 '17 at 10:29
I did this using json_encode. The second argument for json_decode had to be true in my case (to return associative array instead of StdClass as the default)
– jamil
Jan 4 '18 at 0:02
I had to use single quotes around
value
attribute. Otherwise the data was being trimmed at the first double quote in the serialized version.– VeeK
Sep 23 '17 at 10:29
I had to use single quotes around
value
attribute. Otherwise the data was being trimmed at the first double quote in the serialized version.– VeeK
Sep 23 '17 at 10:29
I did this using json_encode. The second argument for json_decode had to be true in my case (to return associative array instead of StdClass as the default)
– jamil
Jan 4 '18 at 0:02
I did this using json_encode. The second argument for json_decode had to be true in my case (to return associative array instead of StdClass as the default)
– jamil
Jan 4 '18 at 0:02
add a comment |
You can use serialize and base64_encode from client side,
After then use unserialize and base64_decode to server side
Like as:
In Client side use:
$postvalue=array("a","b","c");
$postvalue = base64_encode(serialize($array));
//your form hidden input
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
In Server side use:
$postvalue = unserialize(base64_decode($_POST['result']));
print_r($postvalue) //your desired array data will be printed here
This should be the correct answer, better than use foreach, you can pass objects into arrays, and multilevel arrays
– Leonardo Sapuy
Jun 23 '17 at 16:32
This answer doesn't get enough credit. Just using serialize() or json_encode() are things that most people have tried and realize fail on the basis of quotation marks by the time they get here. This answer takes it a step further and encodes it in a way that makes that issue irrelevant in an elegant manner. Bravo!
– Kaji
Oct 12 '17 at 6:28
I agree, this should be the correct answer
– barakadam
Jan 19 '18 at 21:29
add a comment |
You can use serialize and base64_encode from client side,
After then use unserialize and base64_decode to server side
Like as:
In Client side use:
$postvalue=array("a","b","c");
$postvalue = base64_encode(serialize($array));
//your form hidden input
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
In Server side use:
$postvalue = unserialize(base64_decode($_POST['result']));
print_r($postvalue) //your desired array data will be printed here
This should be the correct answer, better than use foreach, you can pass objects into arrays, and multilevel arrays
– Leonardo Sapuy
Jun 23 '17 at 16:32
This answer doesn't get enough credit. Just using serialize() or json_encode() are things that most people have tried and realize fail on the basis of quotation marks by the time they get here. This answer takes it a step further and encodes it in a way that makes that issue irrelevant in an elegant manner. Bravo!
– Kaji
Oct 12 '17 at 6:28
I agree, this should be the correct answer
– barakadam
Jan 19 '18 at 21:29
add a comment |
You can use serialize and base64_encode from client side,
After then use unserialize and base64_decode to server side
Like as:
In Client side use:
$postvalue=array("a","b","c");
$postvalue = base64_encode(serialize($array));
//your form hidden input
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
In Server side use:
$postvalue = unserialize(base64_decode($_POST['result']));
print_r($postvalue) //your desired array data will be printed here
You can use serialize and base64_encode from client side,
After then use unserialize and base64_decode to server side
Like as:
In Client side use:
$postvalue=array("a","b","c");
$postvalue = base64_encode(serialize($array));
//your form hidden input
<input type="hidden" name="result" value="<?php echo $postvalue; ?>">
In Server side use:
$postvalue = unserialize(base64_decode($_POST['result']));
print_r($postvalue) //your desired array data will be printed here
answered May 28 '16 at 11:35
Kabir HossainKabir Hossain
1,2321123
1,2321123
This should be the correct answer, better than use foreach, you can pass objects into arrays, and multilevel arrays
– Leonardo Sapuy
Jun 23 '17 at 16:32
This answer doesn't get enough credit. Just using serialize() or json_encode() are things that most people have tried and realize fail on the basis of quotation marks by the time they get here. This answer takes it a step further and encodes it in a way that makes that issue irrelevant in an elegant manner. Bravo!
– Kaji
Oct 12 '17 at 6:28
I agree, this should be the correct answer
– barakadam
Jan 19 '18 at 21:29
add a comment |
This should be the correct answer, better than use foreach, you can pass objects into arrays, and multilevel arrays
– Leonardo Sapuy
Jun 23 '17 at 16:32
This answer doesn't get enough credit. Just using serialize() or json_encode() are things that most people have tried and realize fail on the basis of quotation marks by the time they get here. This answer takes it a step further and encodes it in a way that makes that issue irrelevant in an elegant manner. Bravo!
– Kaji
Oct 12 '17 at 6:28
I agree, this should be the correct answer
– barakadam
Jan 19 '18 at 21:29
This should be the correct answer, better than use foreach, you can pass objects into arrays, and multilevel arrays
– Leonardo Sapuy
Jun 23 '17 at 16:32
This should be the correct answer, better than use foreach, you can pass objects into arrays, and multilevel arrays
– Leonardo Sapuy
Jun 23 '17 at 16:32
This answer doesn't get enough credit. Just using serialize() or json_encode() are things that most people have tried and realize fail on the basis of quotation marks by the time they get here. This answer takes it a step further and encodes it in a way that makes that issue irrelevant in an elegant manner. Bravo!
– Kaji
Oct 12 '17 at 6:28
This answer doesn't get enough credit. Just using serialize() or json_encode() are things that most people have tried and realize fail on the basis of quotation marks by the time they get here. This answer takes it a step further and encodes it in a way that makes that issue irrelevant in an elegant manner. Bravo!
– Kaji
Oct 12 '17 at 6:28
I agree, this should be the correct answer
– barakadam
Jan 19 '18 at 21:29
I agree, this should be the correct answer
– barakadam
Jan 19 '18 at 21:29
add a comment |
Either serialize:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo serialize($postvalue); ?>">
on receive: unserialize($_POST['result'])
or implode:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo implode(',', $postvalue); ?>">
on receive: explode(',', $_POST['result'])
serialize can mess up your quotes or brackets and mix up with html.. I would use accepted answer
– zachu
May 8 '15 at 14:32
add a comment |
Either serialize:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo serialize($postvalue); ?>">
on receive: unserialize($_POST['result'])
or implode:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo implode(',', $postvalue); ?>">
on receive: explode(',', $_POST['result'])
serialize can mess up your quotes or brackets and mix up with html.. I would use accepted answer
– zachu
May 8 '15 at 14:32
add a comment |
Either serialize:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo serialize($postvalue); ?>">
on receive: unserialize($_POST['result'])
or implode:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo implode(',', $postvalue); ?>">
on receive: explode(',', $_POST['result'])
Either serialize:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo serialize($postvalue); ?>">
on receive: unserialize($_POST['result'])
or implode:
$postvalue=array("a","b","c");
<input type="hidden" name="result" value="<?php echo implode(',', $postvalue); ?>">
on receive: explode(',', $_POST['result'])
edited Aug 9 '12 at 20:40
user212218
answered Jul 1 '11 at 11:21
Ēriks DalibaĒriks Daliba
65844
65844
serialize can mess up your quotes or brackets and mix up with html.. I would use accepted answer
– zachu
May 8 '15 at 14:32
add a comment |
serialize can mess up your quotes or brackets and mix up with html.. I would use accepted answer
– zachu
May 8 '15 at 14:32
serialize can mess up your quotes or brackets and mix up with html.. I would use accepted answer
– zachu
May 8 '15 at 14:32
serialize can mess up your quotes or brackets and mix up with html.. I would use accepted answer
– zachu
May 8 '15 at 14:32
add a comment |
it's better to encode first to JSON-string and then encode with base64 eg. on server side in reverse order: use first base64_decode then json_decode functions. so you will restore your php array
add a comment |
it's better to encode first to JSON-string and then encode with base64 eg. on server side in reverse order: use first base64_decode then json_decode functions. so you will restore your php array
add a comment |
it's better to encode first to JSON-string and then encode with base64 eg. on server side in reverse order: use first base64_decode then json_decode functions. so you will restore your php array
it's better to encode first to JSON-string and then encode with base64 eg. on server side in reverse order: use first base64_decode then json_decode functions. so you will restore your php array
answered Jul 1 '11 at 11:15
heximalheximal
8,82843560
8,82843560
add a comment |
add a comment |
If you want to post an array you must use another notation:
foreach ($postvalue as $value){
<input type="hidden" name="result" value="$value.">
}
in this way you have three input fields with the name result and when posted $_POST['result']
will be an array
add a comment |
If you want to post an array you must use another notation:
foreach ($postvalue as $value){
<input type="hidden" name="result" value="$value.">
}
in this way you have three input fields with the name result and when posted $_POST['result']
will be an array
add a comment |
If you want to post an array you must use another notation:
foreach ($postvalue as $value){
<input type="hidden" name="result" value="$value.">
}
in this way you have three input fields with the name result and when posted $_POST['result']
will be an array
If you want to post an array you must use another notation:
foreach ($postvalue as $value){
<input type="hidden" name="result" value="$value.">
}
in this way you have three input fields with the name result and when posted $_POST['result']
will be an array
answered Jul 1 '11 at 11:15
Nicola PeluchettiNicola Peluchetti
62.4k24117166
62.4k24117166
add a comment |
add a comment |
<input type="hidden" name="item" value="[anyvalue]">
Let it be in a repeated mode it will post this element in the form as an array and use the
print_r($_POST['item'])
To retrieve the item
add a comment |
<input type="hidden" name="item" value="[anyvalue]">
Let it be in a repeated mode it will post this element in the form as an array and use the
print_r($_POST['item'])
To retrieve the item
add a comment |
<input type="hidden" name="item" value="[anyvalue]">
Let it be in a repeated mode it will post this element in the form as an array and use the
print_r($_POST['item'])
To retrieve the item
<input type="hidden" name="item" value="[anyvalue]">
Let it be in a repeated mode it will post this element in the form as an array and use the
print_r($_POST['item'])
To retrieve the item
answered Aug 19 '15 at 15:41
Diagboya EwereDiagboya Ewere
565
565
add a comment |
add a comment |
you can do it like this
<input type="hidden" name="result" value="<?php foreach($postvalue as $value) echo $postvalue.","; ?>">
5
Or just use implode ;-)
– Alex
Jul 1 '11 at 11:20
add a comment |
you can do it like this
<input type="hidden" name="result" value="<?php foreach($postvalue as $value) echo $postvalue.","; ?>">
5
Or just use implode ;-)
– Alex
Jul 1 '11 at 11:20
add a comment |
you can do it like this
<input type="hidden" name="result" value="<?php foreach($postvalue as $value) echo $postvalue.","; ?>">
you can do it like this
<input type="hidden" name="result" value="<?php foreach($postvalue as $value) echo $postvalue.","; ?>">
answered Jul 1 '11 at 11:14
genesisgenesis
43.5k1582111
43.5k1582111
5
Or just use implode ;-)
– Alex
Jul 1 '11 at 11:20
add a comment |
5
Or just use implode ;-)
– Alex
Jul 1 '11 at 11:20
5
5
Or just use implode ;-)
– Alex
Jul 1 '11 at 11:20
Or just use implode ;-)
– Alex
Jul 1 '11 at 11:20
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.
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%2f6547209%2fpassing-array-using-html-form-hidden-element%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
1
You need to serialize it in some way. Check out the serialize and json_encode functions. I'd recommend going with the json_encode.
– Gazler
Jul 1 '11 at 11:14