Forums

How to setup server side validation common to all forms

anv2009 19 Dec, 2009
Hello,

There's a great feature "Server Side Validation" one can setup for each individual form.

Is there a way to setup a single common "Server Side Validation Code" that all forms could share?

Thank you.
GreyHead 20 Dec, 2009
Hi anv2009,

Yes I think so, you can certainly include an external file into most of the ChronoForms edit boxes. I frequently do this with the Form HTML because it makes editing easier. I create an 'includes' sub-folder in components/com_chronocontact and then put something like this
<?php
if ( !$mainframe->isSite() ) { return; }
require_once(JPATH_SITE.DS.'components'.DS.'com_chronocontact'.DS.'includes'.DS.'ss_validation.php');
?>
into the ChronoForms ServerSide validation box. Use the same code in each form and the same validation file will be included. You'll need to make sure that the input names are matched up as well.

I don't think I've tested this with ServerSide validation so please let us know if it works.

Bob

PS The if ( !$mainframe->isSite() ) { return; } line is there to prevent ChronoForms from trying to evaluate the code in the site admin. It is needed for formhtml, possibly not for validation.
norguir 23 Dec, 2009
Bob,

This is a great tip. I usually put something like
<?php
  require_once(JPATH_SITE.DS.'components'.DS.'com_chronocontact'.DS.'includes'.DS.'myfile.php'); 
?>
in the Form Javascript field insteadof Form HTML field. This way, it is not overwritten by the form wizard each time I make a change.

In order to keep the Form Javascript require_once at the bare minimum, I also start myfile.php with
<?php
 if ( !$mainframe->isSite() ) { return; }
 ...



norguir
anv2009 24 Dec, 2009
Bob,

I've created an include php file and have moved my common code in there. Unfortunately, the code did not run as expected. I'll run some more tests.

Thanks,
Alex.
This topic is locked and no more replies can be posted.