I send an array from form1.php to form2.php
<input id="hidden_all_headers" type="hidden" name="hidden_all_headers" value="<?php echo json_encode($all_headers_array); ?>">
The inspector in form1.php
<input id="hidden_all_headers" type="hidden" name="hidden_all_headers" **value="[" region","countries_of_origin","visits_in_milions","receipts_in_milions_euro","nights_in_thousands","expenditure_per_visit_euro","cost_per_night_euro","average_length_of_stay"]"="">**
which looks fine.. but in form2.php
--html
<input id="hidden_all_headers" type="hidden" name="hidden_all_headers" value="<?php echo json_decode($_POST['hidden_all_headers'],true); ?>">
</html>
<script type="text/javascript">
var obj = "<?php echo json_decode($_POST['hidden_all_headers']) ?>";
for(var i=0; i<obj.length; i++){
alert(obj[i]);
};
</script>
inspector for form2.php
-- html
<input id="hidden_all_headers" type="hidden" name="hidden_all_headers" **value=""**>
--script
**var obj = "";**
for(var i=0; i<obj.length; i++){
alert(obj[i]);
};
$('#hidden_all_headers').val(obj);
Can you please help me out why I can not receive the array in form2.php?
Thanks in advance.
My Answer:
It looks like the issue might be with how you are trying to decode the JSON array in form2.php.
In form2.php, when you are trying to decode the JSON array using json_decode($_POST['hidden_all_headers']), you need to pass the second parameter as true to get an associative array.
So, you should update your code in form2.php as follows:
php
This should help you receive the array in form2.php. Let me know if you need any further assistance.
Rate this post
5 of 5 based on 1964 votesComments