Where to enter code in Event switcher

omidhz 08 Apr, 2017
In Chronoforms v5 there was a box for code in Event Switcher. That area does not exist in Chronoform v6. I'm not sure where to enter the code for event switcher then? Instead there is a box "Data Provider" in V6, which I'm assuming has something to do with this, but I don't know how to use it.
I appreciate any input.
Max_admin 08 Apr, 2017
1 Likes
Hi omidhz,

Yes, in v6 you can do the same but using 2 actions:
#1- a PHP action, will take the PHP code withOUT tags, and will "return" some value.
#2- an Event switcher, and in the data provider please use this: {var:php_function_name}, where "php_function_name" is the name of the PHP function (the name of any action is inside a black label)

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
omidhz 08 Apr, 2017
Max,
Thank you for your quick reply.
Here is what I did so far:
I have a php with name age_calculator. I placed it as first action in submit. Here is my php code that I'm using to calculate age based on the date of birth entered in the form:
// Simplify variables
$dob = $form->data['dob'];

//Calculate Age
//explode the date to get month, day and year
  $dob = explode("/", $dob);
  //get age from date or birthdate
  $age = (date("md", date("U", mktime(0, 0, 0, $dob[0], $dob[1], $dob[2]))) > date("md")
    ? ((date("Y") - $dob[2]) - 1)
    : (date("Y") - $dob[2]));

$form->data['age'] = $age;

// Load appropriate event from event Switcher.

if ( $form->data['age'] >= 18 ) {
  return 'adult';
 break;
} else {
  return 'young';
  break;
}


Then I have event switcher, with following settings:
Data Provider: {var:age_calculator}
Events: adult,young
I have an event loader in each event that should load appropriate event.
Unfortunately, this form is running the first event (adult) every time no matter what the date of birth is. Here is my debug data:
Array
(
    [option] => com_chronoforms6
    [chronoform] => pps-0-age
    [event] => submit
    [dob] => 08/12/1971
    [submit] => 
)


It seems like my php code is not calculating the age appropriately. I think I have a problem with how I'm calling the variables, but I'm not sure how. This is the same php code that I used in v5 and it worked perfect.

Attached is a screenshot of my Events for better clarification.
Thanks again. I love V6 and I don't want to go back to V5. I'm converting all my forms to V6
Max_admin 08 Apr, 2017
Answer
1 Likes
Hi omidhz,

There is no $form->data any more in v6, its now called $this->data["dob"], you can use it in array format or as a function:
$this->data("dob"), the 2nd parameter to this function is a default value in case the "dob" field did not exist.

Best regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
omidhz 09 Apr, 2017
1 Likes
Thanks Max.
That did the trick.
This topic is locked and no more replies can be posted.