PDA

View Full Version : submit array



king-greg
5 Feb 2010, 7:20 AM
hello

i try to submit a multidimentional array to PHP form.

it doesnt seem to work
well i try something more simple by this :

Extjs :

var coucou = new Array(2);
coucou[0]='coucou';
coucou[1]=' greg';

tab1.form.submit({ scope:this, waitMsg:'Doing someting',url:'data/traitement.php', method:'POST', params:{carton:coucou},
success: function(form, action ) {
// Ext.Msg.alert('Success?', action.result.success );
Ext.Msg.alert('Data returned.', action.result.data.jsonresult );
}
});


PHP :

<?php

$test = $_POST['carton'];

$jsonresult = json_encode($test);
echo $jsonresult;

?>


but i only get "greg"

how can i pass an array to php form using json ???

thank you

PCSpectra
5 Feb 2010, 8:11 AM
What I would do, is POST a single variable that holds the JSON data, on the server pull on that single variable, convert it to a JSON object or native PHP multi-dimensional array and go to town as required.

Cheers,
Alex

king-greg
8 Feb 2010, 12:53 AM
what kind of variable could holds json data??
a php array ??

king-greg
8 Feb 2010, 7:41 AM
ok

i succeed to have my multi dimensional array in php

i do this to send data:
tab1.form.submit({ scope:this, waitMsg:'Doing someting',url:'data/traitement.php', method:'POST', params:{carton:Ext.encode(semtab)},

and in php :

$carton[] = json_decode(stripslashes($_POST['carton'])) ;

but i still got an error :

[0] => Array\n ext-all-debug.js (ligne 7919)

what is this ?

Mike Robinson
8 Feb 2010, 7:59 AM
As you know: "JSON data" is stored in a character string data type.

As you discovered: sometimes when sending arrays or structures you must encode and decode the data yourself.

I have encountered situations where, when the JSON data was decoded, part of that data wound up as a "string value" that I had to decode a second time. The decoding process, in other words, "did not go far enough" the first time. I do not know exactly why ... I don't know which computer did it ... and have never bothered to pursue it. But it can happen.

You need to use a tool like FireBug (the debugger add on for Firefox) which can show you what the client and the host are saying to each other. You can see the actual way that the data is being encoded (whether it turns out to be "correct" or not!).

As they say: "a picture is worth a thousand words."