Modify Data

rtobias 25 Apr, 2017
How would I use the Modify Data action?

In CF5, I would use a Custom action with php code:

<?php
$form->data['id'] = $form->data['Data2']['id'];
$form->data['eid'] = $form->data['Data2']['id'];
$form->data['email'] = $form->data['Data2']['email'];
$form->data['first_name'] = $form->data['Data2']['first_name'];
$form->data['last_name'] = $form->data['Data2']['last_name'];

$form->data['civicrm_contact_id'] = $form->data['Data2']['civicrm_contact_id'];
$form->data['created_date'] = $form->data['Data2']['created_date'];
$form->data['modified_date'] = $form->data['Data2']['modified_date'];
$form->data['ordering'] = $form->data['Data2']['ordering'];
$form->data['state'] = $form->data['Data2']['state'];
$form->data['checked_out'] = $form->data['Data2']['checked_out'];
$form->data['checked_out_time'] = $form->data['Data2']['checked_out_time'];
$form->data['created_by'] = $form->data['Data2']['created_by'];

$form->data["code"] = "";
?



I could do similar in CF6 using a PHP action in the Custom section and this code:

$this->data['id'] = $this->data['Data2']['id'];
$this->data['eid'] = $this->data['Data2']['id'];
$this->data['email'] = $this->data['Data2']['email'];
$this->data['first_name'] = $this->data['Data2']['first_name'];
$this->data['last_name'] = $this->data['Data2']['last_name'];

$this->data['civicrm_contact_id'] = $this->data['Data2']['civicrm_contact_id'];
$this->data['created_date'] = $this->data['Data2']['created_date'];
$this->data['modified_date'] = $this->data['Data2']['modified_date'];
$this->data['ordering'] = $this->data['Data2']['ordering'];
$this->data['state'] = $this->data['Data2']['state'];
$this->data['checked_out'] = $this->data['Data2']['checked_out'];
$this->data['checked_out_time'] = $this->data['Data2']['checked_out_time'];
$this->data['created_by'] = $this->data['Data2']['created_by'];

$this->data["code"] = "";


I assume the Modify Data action was included to make this easier maybe?
Max_admin 26 Apr, 2017
Hi Randy,

Yes, in the data provider you could add: {data:Data2}, and then you could access the new data set using {var:modify_daya_fn_name}, you can use that to pass the new data set to a data save function for example.

But you may also modify the new data set using the data override, you could add this:

created_by:111

So you would get the full Data2 data but the "created_by" value would not be the same, it would be "111" instead.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
rtobias 26 Apr, 2017
Thanks a bunch, Max. I'll give it a try.

I think this also answers another question of mine: If we are using the line separated list of conditions for a DB action, I'm assuming we would be listing the conditions as:
field_name:value


So if I wanted to read a row as defined by a contact id I have in a url param (I use eid), I would simply use a php action named getEid:
return $_GET['eid'];


And in my DB Read action's Where section:
eid:{var:getEid}
Max_admin 26 Apr, 2017
Hi Randy,

That would work, but there is a shortcode for getting the request parameters directly:

{data:eid}

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
rtobias 28 Apr, 2017
Everything is still working great, but I was just wondering, what happens if you have a url param with the same name as a field? As I understand it, they would both be referenced as stated in the instructions:

{data:PARAMETER_NAME}
Get a url parameter or a form input value.

Is there a priority (like if you have a field named "eid" and a url param, also named "eid", {data:eid} returns the value of the field)?
Max_admin 28 Apr, 2017
Answer
Hi Randy,

Yes, the field value has priority because its in the post array.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
rtobias 28 Apr, 2017
Great, thanks for clarifying.
This topic is locked and no more replies can be posted.