Hello,
<?php
//var_dump($_POST);
if (isset($_POST['data'])) {
var_dump($_POST['prop']);
var_dump(json_decode($_POST['prop-a']));
var_dump(json_decode($_POST['prop-b']));
}
?>
<html>
<form method="post">
<input name="prop[]" value="This" />
<input name="prop[]" value="Is" />
<input name="prop[]" value='"Array"' />
<input name="prop-a" value="Hello" id="element" />
<textarea name="prop-b" rows="4" cols="50"
>{
"a": "str='hello'",
"b": 2
}</textarea>
<input name="data" value='"Submit !"' type="submit"/>
</form>
<script type="text/_javascript_">
let playlist = {
'DADJU & ANITTA' : "let's go \"mon soleil\"",
};
var elt = document.getElementById('element');
elt.value = JSON.stringify(playlist);
</script>
</html>
Regards,
Le sam. 16 oct. 2021 à 01:55, John <john.iliffe@xxxxxxxxx> a écrit :
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
============