366
Hi everyone.
I'm getting to the stage where my only issue with PHP and XOOPS is form validation. It is such a pain to do form validation in code so I've started looking into a possible solution.
One that did catch my attention is SmartyValidate. This works by adding validation in the html itself as Smarty markup.
More information can be found
here. So an example html page would be :
<form method="POST" action="index.php">
{validate field="FullName" criteria="notEmpty" message="Full Name cannot be empty"}
Full Name: <input type="text" name="FullName">
{validate field="Date" criteria="isDate" message="Date is not valid"}
Date: <input type="text" name="Date">
<input type="submit">
</form>
The validation works by :
session_start();
require('Smarty.class.php');
require('SmartyValidate.class.php');
$smarty =& new Smarty;
// required initialization
SmartyValidate::connect($smarty);
if(empty($_POST)) {
$smarty->display('form.tpl');
} else {
// validate after a POST
if(SmartyValidate::is_valid($_POST)) {
// no errors, done with SmartyValidate
SmartyValidate::disconnect();
$smarty->display('success.tpl');
} else {
// error, redraw the form
$smarty->assign($_POST);
$smarty->display('form.tpl');
}
}
I know that $XoopsTpl is extended from the Smarty class so the above example code can be tweaked to work (in theory anyway). I've had a very brief play with this (30 mins) without any luck.
Another interesting website with a solution can be found
here.
Personally I prefer the SartValidate solution but that would involve uploading the smarty plugin files and SmartyValidate into class/smarty. Although not difficult itself it can becomre tedious when updating several sites etc.
So the quaestion is: has anyone implemented a good validation scheme that is reusable? Is one planned for Xoops? Would anyone be interested if I attempted to integrate either of the above two solutions into Xoops? I know XoopsForms has simple required tags that can be added but that is as far as it goes :(
Thoughts, suggestions and ideas are most welcome.
Cheers.
McNaz.