S.M_Emamian S.M_Emamian - 1 month ago 4
JSON Question

How to get json value of input form in codeigniter

I have a

json
variable and I want to post it as a
json
format.

$json_value = json_encode($my_array);
...
echo '<input name="myvalue" type="hidden" value="'.$json_value.'" />';
...


in my function :

$posts = $this->input->post();
echo $posts['myvalue'];


but it is empty .

my
form
works correctly as I can fetch other values of inputs .

Answer

Change Your input to use single quotes inside

echo "<input name='myvalue' type='hidden' value='$json_value'  />";

since you are using double quotes inside and $json_value also has double quotes so there is a conflict.

Comments