Passing an array using an HTML form hidden element
Use:
$postvalue = array("a", "b", "c");
foreach($postvalue as $value)
{
echo '<input type="hidden" name="result[]" value="'. $value. '">';
}
And you will get $_POST['result']
as an array.
print_r($_POST['result']);
Is it possible to pass an array in a form as a hidden field?
You can pass the id of the parent job in the hidden field
, on form submit action you can get the parent id and retrieve the information of that job.
<input type="hidden" name="parent_job_id" value="<?php echo $jobId; ?>">
Make sure which index
holding the id of the parent job.
It seems $job
is an array
, you can not echo
it, you can echo
its index.
Passing a multidimensional array through hidden input via POST
You just need to encode array to json and decode it on action page
echo '<input type="hidden" name="itemsArr" value="'.json_encode($itemsArr). '">';
And at your action Page just decode it
$itemsArr = json_decode($_POST['itemsArr'],true)
pass php multidimensional array from html hidden field to php
finally after trying lot of method this one worked for me with using serialize and unseiralize.
HTML:
<input type="hidden" name="data" value="<?php echo htmlspecialchars(serialize($data)) ?>">
PHP:
$excel = unserialize($_POST["data"]);
How to pass php array in input type hidden in html form
If I'm understanding you correctly, you can try this:
<form method="post" action="next.php">
<input type="hidden" name="my_form_data" value="<?php echo htmlspecialchars(serialize($my_arr)) ?>">
<button name="submit_btn">Submit</button>
</form>
Then in next.php
you unserialize to get the PHP data structure back:
<?php
$my_arr = unserialize($_POST["my_form_data"]);
Passing array to hidden input and retrieve array with elements on different indexes
You can do that in PHP with the function explode. What this function does is split a string into an array by delimiter so in your case, add:
$array = explode(',', $arrayThatHasTheString[0]);
Pass array of objects as hidden field value into mvc controller
@FrenkyB You could change the binding to be a string and then digest it into a list like this.
public void Test(int celo, string pispis, string userji)
{
var myList = JsonConvert.DeserializeObject<List<User>>(userji);
//stuff
}
Javascript - Storing array of objects in hidden field
You can parse your array into a JSON-string to store it:
.push()
is a function, therefore it needs ()
and not the []
array-syntax.
var elems = [];
elems.push('1');
elems.push('2');
elems.push('3');
$('#input_hidden_field').val(JSON.stringify(elems)); //store array
var value = $('#input_hidden_field').val(); //retrieve array
value = JSON.parse(value);
To create an object just change the definition of elems
and the storage of the values:
var elems = {};
elems[0] = '1';
elems[1] = '2';
elems[2] = '3';
Demo
Reference
.stringify()
.parse()
Related Topics
Why Are Escape Characters Being Added to the Value of the Hidden Input
Does PHP Close the File After the File Handler Is Garbage Collected
PHP Object of Class Dateinterval Could Not Be Converted to String
Foreach Loop and Reference of &$Value
Simple Form Not Sending Data via _Post
Isset() Function Is Returning True Even When Item Is Not Set
How to Format Numbers to Have Only Two Decimal Places
How to Store Configuration Variables in PHP
How to Add a Method to an Existing Class in PHP
Fatal Error: Call to Undefined Function Mcrypt_Encrypt()
What Http Status Code Is Supposed to Be Used to Tell the Client the Session Has Timed Out
Convert a JSON into a Utf-8 String
PHP SQL Select Where Like Search Item with Multiple Words
Cannot Use Concatenation When Declaring Default Class Properties in PHP
Natural Sorting Algorithm in PHP with Support for Unicode