Blessan Kurien Blessan Kurien - 1 year ago 49
PHP Question

Reading json string from textfield in php when form submitted

I am trying to read json string from input hidden filed on form submit

<form action="<?=base_url()?>update-basic" method="post" enctype="multipart/form-data">
<input type="hidden" name="old_image" value="<?=json_encode($package_detail->slider_image)?>">
<button type="submit" value="Update" class="btn btn-sm btn-primary">Update</button>

Here the json string comes from database i want to get the json string in server side when the form is submitted



but i will get empty string as the value of

However the json string correctly printed in html

<input type="hidden" name="old_image" value=""{\"0\":\"FB_IMG_1.jpg\"}"">

I am using codeigniter

Answer Source

try this

<input type="text" name="old_image" value='{"0":"FB_IMG_1.jpg"}' />


  $ss = '{"0":"FB_IMG_1.jpg"}';

 echo "<PRE>";
 echo "</PRE>";



    [0] => FB_IMG_1.jpg