4
Hi Antoine,
Like you, I have searched for a method to cleanly implement form validation in XOOPS but have not come up with anything usable. There are a few solutions out there (include a promising Smarty based validation engine) but integrating it into XOOPS without hacking the core files (or Smarty class) was almost impossible.
In the end I had to develope a new base class, based on XoopsObject, that would include validation routines, then base all my classes on this.
This meant that I could define :
$this->initVar('zip', XOBJ_DTYPE_TXTBOX, null, true, 50, 'Post Code/Zip');
in the class constructor, for example. This class would then have a validator which would then spit out an array of errors, indexed by field name, for display to the user.
When a form is posted, check the validation. If no errors then save, otherwise, redisplay the form with the passed errors array.
The HTML will look something like
<input type="text" name="zip" value="<{$myvar.zip}>"><div class="error"><{$errors.zip}>div>
HTH.
Cheers.
McNaz.