Re: Mangled Data

[email protected] (Glash Gnome)
Newsgroups php.general
Message-ID <CADeZBNa7zm4mGKvxD+dU4+YAV92zyfX9_KM5fA7n8cWuSG0d5w@mail.gmail.com>
Hello,

Can you modify this example to show the issue ?

<?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 <[email protected]> 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
> ============
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.