Fork me on GitHub

Form inputs?  Bottom

  • 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?
  • The only one I can think of is to cast any returned values to type.

    e.g.

    Code

    $var = (int)pnVarCleanFromInput('myvar');


    or

    Code

    $var = intval(pnVarCleanFromInput('myvar');


    -Mark

    --
    Visit My homepage and Zikula themes.
  • Don't change the core code all over the place and forget to document it. It makes upgrading a big pain! ;)
  • Oh, I'm not planning on changing the core code, just my validation of data I receive through the module. I'd be too scared that I'd nuke the Nuke. :)
  • 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 :)
  • 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.
  • 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.

This list is based on users active over the last 60 minutes.