Mangled Data

From: Date: Fri, 15 Oct 2021 23:55:04 +0000
Subject: Mangled Data
Groups: php.general 
Request: Send a blank email to php-general+get-327755@lists.php.net to get a copy of this message
PHP 7.2.9 An incoming JSON string is not acted on in this script; just passed through to the next script. I do the following, where 'trans' is a JSON string: (ie result of JavaScript stringify() command) if (isset($_POST['trans'])) { $ord_jdata = $_POST['trans']; .... <form method="POST" name="order" id="order" onSubmit="finished()" action="....> <input type="hidden" name="trans-1" id="trans-1" value= <?php echo $ord_jdata ?> > </form> When this is submitted the data stored in form.trans-1 is NOT the same as the data in $ord.jdata, specifically the following component, as shown by the Firefox devtools | inspector command no longer has the escape \ before the " character. The JSON data contains a string (part of an array) that, when received is: ... ,\"name\":'"some data is found here\", ... but this is stored in the form input field as: ... ,\"some" data="" is="" found="" here=\", which is not at all the same thing. Apparently the spaces within the string are being treated as delimiters for null parameters. Experimenting, I can do a valid/correct json_decode on the incoming data; it just doesn't copy properly. After reading the JSON part of the PHP manual I can't see why this should be so and I suspect that I have run over some constarint on data formatting but I don't see it. Can anyone help?? Thanks in advance. John ============

« previous php.general (#327755) next »