In the "Table List" I cannot find the suitable formula to report in the Patch field to connect the json array {"1": "Roberto", "2": "Venturae", "8": "Via Torino", " 9 ":" 3273333333 ...)
How to do?
Grazie
To create a field to receive a json array in a SQL table, you have just to create a field in Text format.
If you have an array like
1=>Roberto
2=>Venturae
8=>Torino
You have to save this field like {data.join[,]:array_var_name}
You can explode this field like {data.split[,]:table_field_name}.
Sorry but I don't understand. The problem is with Connectivity. I can connect and read the "Calessini" table. In the Repo section I have to show every single field of the record and then I recall the path of every single field as "ID" or "created" or "ipaddress", but if in the next path I type the name of the "DATA" field, the listing will show the 'array: "1": "Eriberto", "2": "Genovese", "8": "sia3", "9": "327351122 .... Instead in that column I should get only the single field" 1 "(which in the form is" name "):"Eriberto ".
The principle:
1 - You have to use a PHP action to rebuild your array, using json-decode php function (look at this: https://www.php.net/manual/en/function.json-decode.php)
2 - You have to write this array in a data field of your form
3 - You have to use something like {data:data_field.1}
Do you know to do this?
I read the article you recommended and I understood the logic. If I'm not wrong I should decode the json string:
$ strjson = '{"1": "Eriberto", "2": "Genovese", "8": sia3 "
} ';
$ carrel = json_decode ($ strjson);
echo $ carrel-> 1; (result) // Eriberto
echo $ carrel-> 2; ( " ) //Genoese
echo $ carrel etc.
If this is right and not knowing Connectivity yet,
where do i find the "data field of your form"?
Finally, it is the string: $ carrel-> 1; the one that will be reported in the Path of the Table Columns?
Thanks again
where do i find the "data field of your form"?
I mean the data json field of your Cassini table.
1 - Decode the json field to have an array (with {data,split[,]:table.model.json-field} or with a PHP action) and put this array in a var.
2 - Use this var in your table column
I've no tried. Just a principle...
Ps. But, you're Italian?
And my english is very bad. I'm not sure that I have fully understand what you want.
I have created a measurement form that the customer sends me. It works perfectly and I see it from the "Log" link in the forms menu:
Now I want to create the Report of all the modules received, so I use Connectivity
I create the form following the tutorial on youtube: https://www.youtube.com/watch?v=raXqQcU_OB8&list=PLNdPw6Bog3zcuSKs7NGNi8QPtfj5IsxQA&index=10
and everything works until, in the database, it has to read the "data" field where the Json string is.
As you already wrote, I have to decode the Json string and convert it to "var" and report every "var" in every "Path" of the "Table Colums" Okay?
And now the problem: having the Connectivity form in use (which I know very little) in which section and / or field should I report the code that explodes the Json string?
I hope I was clear and I trust in your patience ...
Suppose that I have a php var like this:
$strjson= '{"1":"Eriberto","2":"Genovese","8":"sia3"}';
I have to decode this var:
$tmp = json_decode ($strjson,true);
The result is:
[em]Array ( [1[/em]
To use an array in a radio group (or a checkboxes group, …), this array do have a model, like this:
Array
(
[0] => Array
(
[model] => Array
(
[value] => 1
[option] => Eriberto
)
)
[1] => Array
(
[model] => Array
(
[value] => 2
[option] => Genovese
)
)
[2] => Array
(
[model] => Array
(
[value] => 8
[option] => sia3
)
)
)
So I have to rebuild my $tmp array like this:
$myvar=array(); $i=0;
foreach ($tmp as $value => $option) {
$myvar[$i]['model']['value']=$value;
$myvar[$i]['model']['option']=$option;$i++;
};
To use $myvar in CF7, I do this:
$this->set("myvar",$myvar);
So {var:myvar} is an array with a model named model.
In my radio group, I delete all manual Options and I add a Dynamic Option:
Data source: {var:myvar}
Option value: {var:model.value}
Text Value: {var:model.option}
Enjoy!
I understand the system for decoding the Json string. The simple problem is where do I have to write the formulas in Connectivity to make them work ?.
View Table List:
Data Sources: {var:myvar}
Path: model.option, Header:Option
Path:model.value, Header:value
I do that and its works very well. Look at this:
https://www.olympe-retraite-sportive.com/index.php?option=com_chronoforms7&chronoform=form-23oct22-0448
I you want to use different sources, you have to add other datas in myvar array or insert myvar array in your read_data.
Now it remains for me to understand where to insert the decoding code of the json string. (in which area of Connectivity)
To insert the json_field in PHP action, you have to pass the variable read_data.model.json_field to PHP.
At the top of my code, replace...
$strjson= '{"1":"Eriberto","2":"Genovese","8":"sia3"}';
by
$strjson=$this->get("read_data.model.json_field","");
At the end of the PHP action, the result is in the CF7 variable myvar.
Insert an Action Message after the PHP Action to see it, in wich you write:
My var =
{var.pr:myvar}
OK?
Then you have to use this var in a TableView field
View Table List:
Data Sources: {var:myvar} //You have to write yourself {var:myvar}
Path: model.option, Header:Option
Path:model.value, Header:value
Edit:
I've add ID field in my Table View: look at...
https://www.olympe-retraite-sportive.com/index.php?option=com_chronoforms7&chronoform=form-23oct22-0448
Nota: I've using a Read Database with Select = First Record. I think it's more difficult with Select = All Matching Records. I'm not sure that it's possible because this is a non sense.
I know I'm getting unbearable ....
The code is clear to me and I thank you. The problem is where to apply it.
When you write:
"Then you have to use this var in a TableView field
View Table List:
Data Sources... ecc
I use the Table List in the Views Section of Connectivity.
but what I would like to understand is
where to write the code "$ strjson = $ this-> get (" read_data.model.json_field "," ");"
In which section and in which field of connectivity should I write it?
always in the Table list? (I do not think so)
Thank you
In your PHP Action, copy this:
//I Suppose your read Data Base is named read_data_8, with Model named Model8
$tmp=json_decode($this->get("read_data_8.Model8.json",""));
echo "<h4> </h4><h4><strong>Json field:</strong> ".'{"1":"Eriberto","2":"Genovese","8":"sia3"}'."</h4>";
echo "<h4><strong>Json_decode:</strong></h4>";
print_r($tmp);
/*Ajout d'un modèle*/
$myvar=array(); $i=0; $id=$this->get("read_data_8.Model8.id","");
foreach ($tmp as $value => $option) {
$myvar[$i]['model']['id']=$id;
$myvar[$i]['model']['value']=$value;
$myvar[$i]['model']['option']=$option;$i++;
};
echo "<h4> </h4><h4><strong>Variable myvar:</strong> </h4>";
print_r($myvar);
/*retour vers CF7*/
$this->set("myvar",$myvar);
