Forums

Include or require statement

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.
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
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
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.
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.