- Moderated by:
- Support
-
- rank:
-
Helper
- registered:
- November 2004
- Status:
- offline
- last visit:
- 12.03.07
- Posts:
- 387
After my PHP class, I'm all ready to go back into my modules and do some fine tuning. I relaly want to examine my validation procedures. Or make some, anyway.
pnVarCleanFromInput seems to do a good job at taking care of most of the nasties. Apart from making sure that the input is approximately what it should look like, does anyone have recommendations on other steps to take? -
- rank:
-
Moderator
- registered:
- March 2002
- Status:
- offline
- last visit:
- 26.08.08
- Posts:
- 7720
The only one I can think of is to cast any returned values to type.
e.g.
Code
$var = (int)pnVarCleanFromInput('myvar');
or
Code
-Mark -
- rank:
-
Freshman
- registered:
- July 2006
- Status:
- offline
- last visit:
- 16.08.06
- Posts:
- 11
You could also check the format of the input, although requiring a very specific format is something you should try to avoid.
Using a form validation tool sounds like something you'd like. The only one I've tried is Smarty Validate, which works well. Let us know if you find something better :)
--
Erik from www.TenTonHammer.com -
- rank:
-
Helper
- registered:
- June 2002
- Status:
- offline
- last visit:
- 09.09.08
- Posts:
- 288
I just came up with one last month which works pretty well. Its based on a turtorial found on LimitLess Studios. I'll zip it up tonight when I get home and put it online to download.
--
cyber_wolf
www.bkbsolutions.com - My Zikula module development site. -
- rank:
-
Helper
- registered:
- June 2002
- Status:
- offline
- last visit:
- 09.09.08
- Posts:
- 288
I've put the form validation class online. It can be downloaded here.
Here's a small example on how to use it.....
Code
require_once 'modules/bkbResources/pnincludes/FormValidate.php';
function bkbResources_admin_entries_new($args)
{
list($title,
$url,
$email,
$validate) = pnVarCleanFromInput('title',
'url',
'email',
'validate');
$vObject = new FormValidate;
if (!empty($validate)) {
$vObject->addFormField('title','isRequired',$title,_bkbResourcesErrorRequiredTitle);
$vObject->addFormField('url','isRequired',$url,_bkbResourcesErrorRequiredSiteURL);
$vObject->addFormField('url','isURL',$url,_bkbResourcesErrorURLSiteURL);
$vObject->addFormField('email','isEMail',$email,_bkbResourcesErrorEMail);
if ($vObject->validate()) {
pnModFunc('bkbResources',
'admin',
'entries_create',
array('title' => $title,
'url' => $url,
'email' => $email));
} else {
pnSessionSetVar('errormsg', _bkbResourcesErrorMessages);
}
}
$pnRender =& new pnRender('bkbResources');
$pnRender->caching = false;
$Errors = $vObject->getFormErrorList();
}
There are instructions in the class on how to use it as well as all the validations that are included; and more can be easily added.
--
cyber_wolf
www.bkbsolutions.com - My Zikula module development site.
