Menu

#234 Validations All Forms Xoops for Devs

XOOPS_2.0.x
open
Core (214)
7
2012-09-25
2006-09-22
GibaPhp
No

All Forms xoops consistence and validations roles
(javaScript and php) field in field.

folder class/xoopsform

This is implementation consistence for all forms xoops
and liberty for developers chekin field in field for
various validations javascript and formulary too :-)

I very happy for one greate analysing code.

Thanks my Friend, good Work for you.

This is Work TheRpLima and implements GibaPhp :-)

Giba :-)

Discussion

  • GibaPhp

    GibaPhp - 2006-09-22

    Validations All Forms Xoops

     
  • Skalpa Keo

    Skalpa Keo - 2006-09-23

    Logged In: YES
    user_id=882380

    You missed a point...
    The change I did in 2.0.15 does exactly this.

    The only difference is that you called the function for
    custom validation "getEspecValid", while I decided to call
    it "renderValidationJS". So there is no need to add the same
    thing 2 times.

    Now, the 2.0.15 code requires that people make a custom
    class, so I may make it a little easier, to allow people to
    do things like this:

    $elt = new XoopsFormText( "caption", "title", 50 );
    $elt->customValidationCode = "<put JS="" code="" here="">";
    $form->addElement( $elt );

    I'll do it and tell you...

    Just 2 comments anyway:
    - If you add something to a base class (here:
    XoopsFormElement) there is no need to put it again in all
    children classes (XoopsFormText, XoopsFormTextarea, etc...).
    This is actually what Object-Oriented programming and
    classes is about: you put "common" functionality in base
    classes, so you don't have to duplicate the same code
    everywhere.
    - When you need to add a property to an object (in your
    code: "especvalid") you don't have to make get/set functions
    (like getEspecValid/setEspecValid). You can let people
    access the property directly by doing: $elt->especvalid =
    "value". I know XOOPS is full of these ugly things
    everywhere, but this is very bad habits... The fact mistakes
    were done in the past does not mean we have to make them
    again and again. So please do not use this in your code,
    unless you really need to: your code will be easier to
    understand, and faster. :-)

     
  • Skalpa Keo

    Skalpa Keo - 2006-09-23

    Logged In: YES
    user_id=882380

    K Giba... I did it, you can have a look here:
    http://svn.sourceforge.net/viewvc/xoops/XoopsCore/branches/2.0.x/2.0.16/htdocs/class/xoopsform/formelement.php?annotate=751
    and tell me what you think.

    A few details for you:
    - The function I added has been put in XoopsFormElement,
    which is the base class used everywhere in XoopsForm.
    Because of this, you can use it in text,textarea,select,
    always :-)
    - The property I put is an array, so you can add several
    validation rules easily.

    Here is an example of use, to make a form element that can
    only contain letters and be at least 6 characters:

    $elt = new XoopsFormText( "Enter value", 'checkme' );
    $elt->customValidationCode[] = "if
    (myform.elements.checkme.length < 6 ) return false;";
    $elt->customValidationCode[] = "if (
    !myform.elements.checkme.match(/^[a-z]*$/) ) return false;";
    $form->addElement( $elt );

     
  • GibaPhp

    GibaPhp - 2006-09-23

    Logged In: YES
    user_id=1129857

    OK, I'll take care of this one personally.

     
  • GibaPhp

    GibaPhp - 2006-09-23

    Logged In: YES
    user_id=1129857

    I am ready your orientation abou duplicate code, yes, i
    agree and thanks for explanation. :-)

    About customization roles javascript and validations
    back-end php, i am review all implements and tests for no
    comprometed my forms with this new enfoque.

    I really example for include in unique class and herance, is
    good form, i agree and go to view it :-)

     

Log in to post a comment.