Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.ajax({
- data:{'async':$('#form').serializeArray()},
- type:"POST",
- async: true,
- success: function(data) {
- $("#container").html(data);
- },
- failure: function(data) {
- alert('error');
- }
- });
- $form->setData($request->getPost('async'));
- if (! $form->isValid()) { /*do stuff*/}
- array{
- filedset1=aray{
- el_1.1=>'value',
- el_1.2=>'value',
- [...]
- },
- filedset2=aray{
- el_2.1=>'value',
- el_2.2=>'value',
- [...]
- },
- [...]
- };
- array{
- filedset1[el_1.1]=>'value',
- filedset1[el_1.2]=>'value',
- [...]
- filedset2[el_2.1]=>'value',
- filedset2[el_2.2]=>'value',
- [...]
- };
- $form->setData($this->parseSerializedArray($request->getPost('async')));
- if (! $form->isValid()) { /*do stuff*/}
- [...]
- public function parseSerializedArray($array)
- {
- $result=array();
- foreach($array as $item){
- if (preg_match("/^w+[w+]$/",$item['name'])){
- $str=explode("[",$item['name']);
- $key=$str[0];
- $val=rtrim($str[1],']');
- if (!array_key_exists($key,$result)){$result[$key]=array();}
- $result[$key][$val]=$item['value'];
- }
- //if the element doesn't belong to any fielset...
- else{$result[$item['name']]=$item['value'];}
- }
- return $result;
- }
- $.ajax({
- data:{'async':$('#form').serialize()}, //output: querystring
- async: true,
- success: function(data) {
- $("#container").html(data);
- },
- failure: function(data) {
- alert('error');
- }
- });
- parse_str($request->getPost('async'),$data);//output: multidimensional array
- $form->setData($data);
- if (! $form->isValid()) { /*do stuff*/}
Add Comment
Please, Sign In to add comment