Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Form inputs?
  • Posted: 11.08.2006, 01:35
     
    jediping
    rank:
    Helper 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?
  • Posted: 11.08.2006, 19:40
     
    rank:
    Moderator 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

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


    -Mark
  • Posted: 11.08.2006, 23:35
     
    personofinterest
    rank:
    Softmore Softmore
    registered:
     April 2006
    Status:
    offline
    last visit:
    17.01.07
    Posts:
    73
    Don't change the core code all over the place and forget to document it. It makes upgrading a big pain! ;)
  • Posted: 12.08.2006, 01:48
     
    jediping
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    12.03.07
    Posts:
    387
    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. :)
  • Posted: 12.08.2006, 03:39
     
    TTH_Erik
    rank:
    Freshman 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
  • Posted: 14.08.2006, 20:39
     
    cyber_wolf
    rank:
    Helper 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.
  • Posted: 15.08.2006, 19:35
     
    cyber_wolf
    rank:
    Helper 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.

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula