Dynamic data in dropdown to show form description

isatyam 18 Aug, 2014
Hi,

I want to create a dropdown which will show the "Description" of all forms created in chronoforms5. I am using a DB read to read the "params" field from the #__chronoengine_chronoforms table. Now what should I write in the element settings of the dropdown element?

Regards,
Satyam
Max_admin 19 Aug, 2014
Hi Satyam,

Assuming your model id in the "db read" is "Form" then you can add this in the "dynamic data" in the dropdown settings:

Model: Form
value: id
text: params.discription

Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
RobP 19 Aug, 2014
There is a lot of other data in the params field.
To use it it has to be cleaned is bit.

[list=]Put a DB Read in the actions and select the chronoengine_chronoforms table
Set the Enable Model ID to Yes an give it a Model ID id_sel (in this example)
In the Fields list: id, params
Save it
Put a Custom Code action in the On found of the DB Read and put the following code in it:[/list]

<?php

$arrlength=count($form->data['id_sel']);

for($x=0;$x<$arrlength;$x++) {
  $id_sel=$form->data['id_sel'][$x]['id'];
  $params_sel=$form->data['id_sel'][$x]['params'];

  $params2=stristr($params_sel, '","setup"', true); 
  $params3=substr($params2, 16);

  $form->data['params'][$x]['id']=$form->data['id_sel'][$x]['id'];
  $form->data['params'][$x]['params']=$params3;
}
?>


This creates a new array with just the ID and the cleaned Params

[list=]In the Designer put a dropdown on the form.
Go to Dynamic Data and set Enabled to Yes
Data Path: params
Value Key: id
Text Key: params[/list]


Rob
RobP 19 Aug, 2014
Hi Max,

Just read your suggestion..
It sound much simpler, but I tried something like that some time ago an couldn't get it to work.

Is it possible t get a value from a Text string like that?
That would save me a lot of time.

Rob
isatyam 20 Aug, 2014
Hi Max,

I tried implementing your suggestion but the dropdown now only shows "{" as options. Rob's suggestion involves a lot of processing, it would be really great if we can have a straightforward method as suggested by you.

Regards,
Satyam
RobP 20 Aug, 2014
My code isn't that bad.

I agree that what Max suggested sounds a lot simpler.
But my experience is that it is a lot less frustrating to write some code that I understand that trying to figure out how something works.

Chronoforms is great, but the documentation could be better, finding the right syntax is often a lot of trial and error (at least for me).

I did a lot of programming in Delphi, always with the 1250 page reference library on my desk.

Rob
GreyHead 20 Aug, 2014
Answer
1 Likes
Hi Satyam,

I don't think that there is a simpler version. Here's my code snippet that is a little simpler than Rob's
<?php
foreach ( $form->data['Form'] as $k => $v ) {
  $temp = json_decode($v['params']);
  // handle the cases when no description is set
  if ( !isset( $temp->description ) || !$temp->description ) {
    $temp->description = 'No description';
  }
  $form->data['Form'][$k]['description'] = $temp->description;
}
?>
This requires 'id' and 'description' in the Dynamic Data boxes. Note that half of the code is used to handle the cases where no description is set for a form.

Bob

PS You can also use this to access any other form parameter - they are all added to the $temp object here.
RobP 20 Aug, 2014
Hi Bob,

I was not familiar with json_decode, looks good!!

One point, I don't think it is a good idea to manipulate a system table, one accidental DB Save and a lot can go wrong!

I always put the results in an other array.

Rob
GreyHead 20 Aug, 2014
Hi Rob,

I take your point but I don't think that there is much danger here as the decoded params are being saved in 'different' array and are very unlikely to over-write the forms table.

There's been a shift away from the older 'ini' file structure for params to a json encoded structure. Personally I find it very useful. When I just want a security backup for my form data I do $form->data['data'] = json_encode($form->data); and save the whole lot to a single 'data' column in the database.

Bob
RobP 20 Aug, 2014
Hi Bob,

Never underestimate the power of Murphy's law.
A lot of people on this forum don't have your expertise with Cronoforms, I certainly don't.

I regularly make a backup with akeeba, and start with a copy of the Joomla files and the Database when trying something new.

Rob
Max_admin 20 Aug, 2014
Bob's post is the correct solution:
http://www.chronoengine.com/forums/posts/t97262/p334869/dynamic-data-in-dropdown-to-show-form-description.html#p334869

I forgot that the params array is json encoded!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.