Forums

Call an Event from Submit Event like a function

MainsailSoftware 24 Dec, 2015
In the spirit of reusing code, I would like to be able to call a Custom Event from within the Submit Event.

I have a situation where I would like to send a confirmation email to an Activity Attendee with slightly different dynamic content dependent on the context in which it is to be sent.
[list=]
[*]When Attendee signs-up using a front-end form.
[*]When an Activity Manager adds an attendee in ChronoConnectivity that uses a CCv5 Edit Action call to a CFv5 form.
[*]When an Activity Manager edits an attendee record using CCv5 Edit Action and changes their status.
[*]When an Activity Manager re-sends a confirmation email using CCv5 custom Resend Action call to the CFv5 form's custom Resend Event.
[/list]
The Activity Manager CCv5 Connection is available in both the Front List and Admin List displays.
The CFv5 form used for Attendee direct sign-up is separate and different from the CFv5 form used for the CCv5 Connection.
Within the Activity Manager CFv5 form for Add and Edit Actions the Submit Event is used and handles the New Attendee vs Existing Attendee status change contexts.
The Activity Manager CCv5 Resend Action uses the same CFv5 form, but calls the Resend Event instead of the Submit one.

This situation forces me to duplicate code in the Attendee Sign-Up CFv5 form, in the Activity Manager CFv5 form's Submit Event, and in the Activity Manager CFv5 form's Resent Event.

I would simply like to be able to call the Activity Manager CFv5 form's Resent Event from both the Activity Manager CFv5 form's Submit Event, and the Attendee Sign-Up form's Submit Event passing the necessary parameters and/or data via session.

I have tried using CFv5 setup action Load Form with action Chrono Redirect, but I cannot seem to get that to work.

I can probably get it to work with CFv5 Redirect setup actions with return URLs passed in, but I was hoping for something simpler and cleaner.
MainsailSoftware 24 Dec, 2015
With a little further experimentation I found the following:
[list]
[*]If I create a separate utility CFv5 form with the Event I need and call it from the original form using only Load Form in the original, it appears to work. I tested by having the utility form Event set something in $form->data, echo some text, then followed by a Data To Session action. In the original form Event I used the Load Form action followed by Session To Data action, and the Debug action. The page shows the echoed text and debug shows the added $form->data item.
[*]If I do the exact same thing, but using a custom event in the original form; having the Submit Event call the custom Event, it does NOT work!
[/list]
MainsailSoftware 24 Dec, 2015
I also tried it without the data to and from Session, and it works fine between two different CFv5 forms.

Wish there I could find some Documentation, FAQ, or other Forum posts on this Load Form action topic!

This may be the solution I was looking for. Waiting for other responses before I decide this is the best approach.
GreyHead 26 Dec, 2015
Hi MainsailSoftware,

I've read this twice but still don't really understand what the question is - maybe because it's a holiday afternoon . . .

I've never used the CFv5 Load Form action but - if I understand it correctly it lets you load one form inside another as a way of including common html.

The core of your question looks to me as if it is a case for using the Event Switcher to handle the different cases assuming that you have sufficient information available to tell you which case you need to run.

Bob
MainsailSoftware 27 Dec, 2015
I probably provided too much information...

I have two separate forms: one used for website users to sign-up for an activity, the other for activity managers to add and edit activity sign-up records for club members who have phone called or emailed the manager directly, manager resend of email confirmation invoice, and to change attendee status when the manager receives a payment check in the mail.

Both forms generate a confirmation email that contains a customized invoice indicating the number of tickets ordered, amount due, check mailing instructions, and other attendee personal information.

This generation of the email and contained invoice is almost identical for each condition: online sign-up, manager performed entry, and manager change of invoice status to Paid.

I currently use Event Switcher in the Manager's Form to deal with Add and Edit contexts, but the Resend context uses a separate custom Event within the Manager's form (no form display, only execution of email generation) with duplicate code.

In a separate form with different content used for member Online Sign-up, I have to duplicate the email/invoice generation code.

The Load Form seems to work great to call the custom Event execution only code (no form displayed), but only works when called between two separate forms. I cannot call the custom Event from within the same form.

This seems to be a BUG, but may be designed to work that way.

Who created Load Form? Maybe they could assist me...
GreyHead 28 Dec, 2015
Hi MainsailSoftware,

Max is the developer and owner of ChronoForms - you can contact him through the Contact Us menu above.

If you want to include the same code in separate forms then you can put it in a file and use code like this to include it into a Custom Code action or element
<?php
include (JPATH_SITE.'/components/com_chronoforms5/extras/folder_name/file_name.php');
?>

Bob
MainsailSoftware 28 Dec, 2015
Thanks Bob, that is useful to know.

The problem is that when I am speaking of "code", I am referring to a combination of ChronoForm Setup Actions and a little bit of PHP code. To duplicate what I need in only PHP would involve a ton of re-coding and the loss the power of ChronoForms Setup Actions, if I were to take the PHP code include approach.

I will send Max a PM and look for his response.
This topic is locked and no more replies can be posted.