Include or require statement

How to reuse validation code across multiple ChronoForms.

Overview

The problem is that including a validation script directly in the event switcher prevents the return statement from working correctly due to scope limitations.
Place the validation code in a separate file and include it using a custom code action above the event switcher. Then, within the event switcher, evaluate the result from the script and handle the return statement there.

Answered
ch chriso0258 17 Aug, 2015
Hello,

I'm finding I'm using pretty much the same validation code in a number of forms and when I have to tweak it, I have to go into each form to do this.

I was thinking of using a require statement in the php code to include a php file that would have the validation code in it. Where would be the best place to put this file so it won't be over-written with new updates?

Thanks.
Gr GreyHead 17 Aug, 2015
Hi Chris,

Please see this FAQ. This was a CFv4 FAQ but I still do the same in CFv5 except that the code to get the form name is a little different so my macro now gives
<?php
include (JPATH_SITE.'/components/com_chronoforms5/includes/'.$form->form['Form']['title'].'/file_name.php');
?>

Bob
ch chriso0258 18 Aug, 2015
Thank you Bob.

The form is reading the script. When an improper character is entered in a field I am getting my error message from the script. However, it is not returning to the event switcher. on fail it should reload the page. on success it should save the data.

Here is what I have in my event switcher.
<h3><p style="text-align: center; background-color: #F2F274;">
<?php
require (JPATH_SITE.'/components/com_chronoforms5/includes/'.$form->form['Form']['transfer_equip_form'].'/validation.php');
?>
</p></h3>


Am I missing something?

Thanks,
Chris
ch chriso0258 18 Aug, 2015
Answer
Hello again,

Never mind. I think I solved the problem. 😶 I used a custom code above the event switcher to call the validation script. I then had the event switcher evaluate the result I sent back from the script. 😀

Regards,
Chris.
Gr GreyHead 18 Aug, 2015
Hi Chris,

Yes, the scope of the included file stops the return working from the file itself, you have to check the result and do the return return from the Event Switcher box.

Bob
This topic is locked and no more replies can be posted.