Validation

View: New views
20 Messages — Rating Filter:   Alert me  
< Prev | 1 - 2 | Next >

Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I did some digging on validation in Knop.

http://www.nabble.com/Validation-possibilities-to14126487.html
http://www.nabble.com/Integrating-Jquery-to20892338.html
http://www.nabble.com/New-version-uploaded-to-SVN-to20716315.html

    2008-09-13 JS ->addfield and ->validate: Implemented -validate
    to specify a compound expression to validate the field input.

Got example?

How do you specify the user-submitted field value in the compound expression?

Where are the validation error message codes/strings specified?

Here's my guess:

    $myform->addfield(
        -type='text',
        -name='answer_to_life',
        ...
        -validate={ $answer_to_life == 42; }
    );

...would return TRUE or non-zero.  I think...?

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Jolle Carlestam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

24 mar 2009 kl. 08.47 skrev Steve Piercy - Web Site Builder:

> ...would return TRUE or non-zero.  I think...?

 From the help text:
Performs validation and fills a transient array with field names that  
have input errors. form -> loadfields must be called first.

HDB
Jolle

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Jolle Carlestam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

24 mar 2009 kl. 09.25 skrev Jolle Carlestam:

>
> 24 mar 2009 kl. 08.47 skrev Steve Piercy - Web Site Builder:
>
>> ...would return TRUE or non-zero.  I think...?
>
> From the help text:
> Performs validation and fills a transient array with field names that
> have input errors. form -> loadfields must be called first.

Sorry, did some more reading:
-validate (optional) Compound expression to validate the field input.  
The input can be accessed as params inside the expression which should  
either return true for valid input or false for invalid, or return 0  
for valid input or a non-zero error code or error message string for  
invalid input. \n\


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Johan Solve-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 00.47 -0700 2009-03-24, Steve Piercy - Web Site Builder wrote:

>I did some digging on validation in Knop.
>
>http://www.nabble.com/Validation-possibilities-to14126487.html
>http://www.nabble.com/Integrating-Jquery-to20892338.html
>http://www.nabble.com/New-version-uploaded-to-SVN-to20716315.html
>
>    2008-09-13 JS ->addfield and ->validate: Implemented -validate
>    to specify a compound expression to validate the field input.
>
>Got example?
Yes, wasn't it included in the LDC code exaples? Oh no, it was a late addition...

Example attached.


>How do you specify the user-submitted field value in the compound expression?

It's available as 'params' inside the validation expression. This is common practice everywhere in Knop where you can use compund expressions.
Remember that compound expressions must return something.


>Where are the validation error message codes/strings specified?

In the validation code, or however you please. No predefined place.
You can return a literal error message, or a made up error code that you translate to a meaningful message yourself.

You can also extend the built-in error codes on the fly:

$myform -> error_lang -> insert(-language='en', -key=9123, -value='Your input is not the answer to life');

(->error_lang comes from knop_base so it's available in all knop types)

I'm not entirely sure how to use the error message you just inserted but one way would be like this:
$myform -> error_msg(-error_code=9123);

Maybe you can use it more elegantly but I would need to do some more research to figure that out.


>Here's my guess:
>
>    $myform->addfield(
>        -type='text',
>        -name='answer_to_life',
>        ...
>        -validate={ $answer_to_life == 42; }
>    );
>
>...would return TRUE or non-zero.  I think...?

More like

    $myform->addfield(
        -type='text',
        -name='answer_to_life',
        ...
        -validate={return(params == 42); } // true means no error
    );

Or
    $myform->addfield(
        -type='text',
        -name='answer_to_life',
        ...
        -validate={return(params == 42 ? 0 | 9123); } // 0 means no error
    );


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:joh-n@...
 (spam-safe email address, replace '-' with 'a')


--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

%validate-form.lasso (176 bytes) Download Attachment
validate-form.lasso (2K) Download Attachment

Re: Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday, March 24, 2009, inbox_js@... (Johan Solve) pronounced:

>>    2008-09-13 JS ->addfield and ->validate: Implemented -validate
>>    to specify a compound expression to validate the field input.
>>
>>Got example?
>
>Yes, wasn't it included in the LDC code exaples? Oh no, it was a late addition...
>
>Example attached.

Whoa.  Dude.  That is cool.

>>How do you specify the user-submitted field value in the compound expression?
>
>It's available as 'params' inside the validation expression. This is common practice
>everywhere in Knop where you can use compund expressions.
>Remember that compound expressions must return something.

I think I understand.  My vocabulary is weak regarding OOP.  So please correct me.

* $myform is an object.
* ->addfield is a method.
* $myform->addfield performs a method on an object.
* What do you call the relationship between params and $myform and ->addfield in the following?

   $myform->addfield(
       -type='text',
       -name='answer_to_life',
       ...
       -validate={return(params==42);}
   );

* params will use whatever gets thrown into it--either action_params, database values or explicit -params--based upon the current action.

One more question: if you have two or more fields that have dependencies for their validation rules, how would you use a -validate?  For example:

    if(
        $email == '' &&
        $phone == '' &&
        $carrier_pigeon == ''
    );
        $error_msg += 'You must provide at least one contact method.'
    /if;

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Jolle Carlestam-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

24 mar 2009 kl. 11.35 skrev Steve Piercy - Web Site Builder:

> One more question: if you have two or more fields that have  
> dependencies for their validation rules, how would you use a -
> validate?  For example:
>
>    if(
>        $email == '' &&
>        $phone == '' &&
>        $carrier_pigeon == ''
>    );
>        $error_msg += 'You must provide at least one contact method.'
>    /if;

I would use getvalue.

    if(
        $fExample -> getvalue('email') == '' &&
        $fExample -> getvalue('phone') == '' &&
        $fExample -> getvalue('carrier_pigeon') == ''
    );
        $error_msg += 'You must provide at least one contact method.'
    /if;

HDB
Jolle

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday, March 24, 2009, jolle@... (Jolle Carlestam) pronounced:

>24 mar 2009 kl. 11.35 skrev Steve Piercy - Web Site Builder:
>
>> One more question: if you have two or more fields that have  
>> dependencies for their validation rules, how would you use a -
>> validate?  For example:
>>
>>    if(
>>        $email == '' &&
>>        $phone == '' &&
>>        $carrier_pigeon == ''
>>    );
>>        $error_msg += 'You must provide at least one contact method.'
>>    /if;
>
>I would use getvalue.
>
>    if(
>        $fExample -> getvalue('email') == '' &&
>        $fExample -> getvalue('phone') == '' &&
>        $fExample -> getvalue('carrier_pigeon') == ''
>    );
>        $error_msg += 'You must provide at least one contact method.'
>    /if;

Cool.

Then would you put -validate into any one of the ->addfields or some other method?

    var('valid_contact' = {
        local('result' = 0);
        if(
            $fExample -> getvalue('email') == '' &&
            $fExample -> getvalue('phone') == '' &&
            $fExample -> getvalue('carrier_pigeon') == ''
        );
            #result += 'You must provide at least one contact method.'
        /if;
        return(#result);
        }
    );
   
    $myform->addfield(
        -name = 'first_name',
        ...
        -validate=$valid_contact
    );

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Johan Solve-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 03.35 -0700 2009-03-24, Steve Piercy - Web Site Builder wrote:

>On Tuesday, March 24, 2009, inbox_js@... (Johan Solve) pronounced:
>
>>>    2008-09-13 JS ->addfield and ->validate: Implemented -validate
>>>    to specify a compound expression to validate the field input.
>>>
>>>Got example?
>>
>>Yes, wasn't it included in the LDC code exaples? Oh no, it was a late addition...
>>
>>Example attached.
>
>Whoa.  Dude.  That is cool.

Jeff? :-P


> >>How do you specify the user-submitted field value in the compound expression?
>>
>>It's available as 'params' inside the validation expression. This is common practice
>>everywhere in Knop where you can use compund expressions.
>>Remember that compound expressions must return something.
>
>I think I understand.  My vocabulary is weak regarding OOP.  So please correct me.
>
>* $myform is an object.

One could also say an instance of a type (or class as it's called in other languages).

>* ->addfield is a method.
>* $myform->addfield performs a method on an object.
>* What do you call the relationship between params and $myform and ->addfield in the following?
>
>   $myform->addfield(
>       -type='text',
>       -name='answer_to_life',
>       ...
>       -validate={return(params==42);}
>   );

Do you mean 'params' in the -validate compound expression? It's just how Knop implements it. When executing the compund expression, it sends the current field value as parameter top the code. Like so:

{code block} -> run(-params=yada);


>* params will use whatever gets thrown into it--either action_params, database values or explicit -params--based upon the current action.

This depends on the Knop implementation in each situation. In this case it pulls the values from where ->loadfields pulls the values. See docs for ->loadfields.


>One more question: if you have two or more fields that have dependencies for their validation rules, how would you use a -validate?  For example:
>
>    if(
>        $email == '' &&
>        $phone == '' &&
>        $carrier_pigeon == ''
>    );
>        $error_msg += 'You must provide at least one contact method.'
>    /if;

Easiest would be to perform the validation in bare code in the action file, after ->loadfields. I don't think you gain anything but pain by trying to use -validate for this. But you can access other field values from within the -validate expression as usual (for example through $myform -> phone) since  validate is run after -> loadfields.


$myform -> loadfields;
   if(
        $myform -> email == '' &&
        $myform -> phone == '' &&
        $myform -> carrier_pigeon == ''
    );
        $myform -> adderror('email') & adderror('phone') & adderror('carrier_pigeon');
                // custom error message
    /if;



--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:joh-n@...
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Johan Solve-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 04.04 -0700 2009-03-24, Steve Piercy - Web Site Builder wrote:

>Then would you put -validate into any one of the ->addfields or some other method?
>
>    var('valid_contact' = {
>        local('result' = 0);
>        if(
>            $fExample -> getvalue('email') == '' &&
>            $fExample -> getvalue('phone') == '' &&
>            $fExample -> getvalue('carrier_pigeon') == ''
>        );
>            #result += 'You must provide at least one contact method.'
>        /if;
>        return(#result);
>        }
>    );
>
>    $myform->addfield(
>        -name = 'first_name',
>        ...
>        -validate=$valid_contact
>    );

Actually that's perfectly fine. I think I withdraw my statement in my reply just now.

But you should but the $valid_contact validation code in the three fields that are involved in this particular validation. This is mostly to be able to highlight them as error fields for better visual feedback.

--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:joh-n@...
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Johan Solve-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 12.10 +0100 2009-03-24, Johan Solve wrote:
> >* params will use whatever gets thrown into it--either action_params, database values or explicit -params--based upon the current action.
>
>This depends on the Knop implementation in each situation. In this case it pulls the values from where ->loadfields pulls the values. See docs for ->loadfields.

Er, actually the params value is pulled from the current field value, since -validate is executed AFTER loadfields.
--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:joh-n@...
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Johan Solve-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 12.12 +0100 2009-03-24, Johan Solve wrote:

>At 04.04 -0700 2009-03-24, Steve Piercy - Web Site Builder wrote:
>>Then would you put -validate into any one of the ->addfields or some other method?
>>
> >    var('valid_contact' = {
> >        local('result' = 0);
> >        if(
>>            $fExample -> getvalue('email') == '' &&
>>            $fExample -> getvalue('phone') == '' &&
>>            $fExample -> getvalue('carrier_pigeon') == ''
>>        );
>>            #result += 'You must provide at least one contact method.'
>>        /if;
>>        return(#result);
>>        }
>>    );
> >
>>    $myform->addfield(
>>        -name = 'first_name',
>>        ...
>>        -validate=$valid_contact
>>    );
>
>Actually that's perfectly fine. I think I withdraw my statement in my reply just now.
>
>But you should but the $valid_contact validation code in the three fields that are involved in this particular validation. This is mostly to be able to highlight them as error fields for better visual feedback.

I'm a bit curious about if it would work to use 'self' in the validation expression, instead of the explicit form variable. Could you try this?

i.e.
var('valid_contact' = {
   local('result' = 0);
   if(
           self -> getvalue('email') == '' &&
           self -> getvalue('phone') == '' &&
           self -> getvalue('carrier_pigeon') == ''
   );
           #result += 'You must provide at least one contact method.'
   /if;
   return(#result);
   }
);


Oh btw, self -> email (just as $fExample -> email) is a shorthand to self -> getvalue('email') thanks to the magics of _unknowntag.


--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:joh-n@...
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday, March 24, 2009, inbox_js@... (Johan Solve) pronounced:

>    $myform->addfield(
>        -type='text',
>        -name='answer_to_life',
>        ...
>        -validate={return(params == 42); } // true means no error
>    );

I've been fumbling through some experiments with -validate, none of which have been successful.  I modified the demo file cfg_advanced_edit.inc, and I kept getting NULL returned no matter what.  Ultimately I did the following:

    $f -> (addfield:
            -type='text',
            -name='lastname',
            -label=$lang_ui -> lastname,
            -required,
            -validate={return(params);},
            -size=40);

When I output the value of $f in cnt_advanced_edit.inc, I get this:

    lastname = map: (name)=(lastname), (validate)=() ...

I expected a value for validate, but there is none.

These are the only two modifications I made.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Johan Solve-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 05.42 -0700 2009-04-06, Steve Piercy - Web Site Builder wrote:

>On Tuesday, March 24, 2009, inbox_js@... (Johan Solve) pronounced:
>
>>    $myform->addfield(
>>        -type='text',
>>        -name='answer_to_life',
>>        ...
>>        -validate={return(params == 42); } // true means no error
>>    );
>
>I've been fumbling through some experiments with -validate, none of which have been successful.  I modified the demo file cfg_advanced_edit.inc, and I kept getting NULL returned no matter what.  Ultimately I did the following:
>
>    $f -> (addfield:
>            -type='text',
>            -name='lastname',
>            -label=$lang_ui -> lastname,
>            -required,
>            -validate={return(params);},
>            -size=40);
>
>When I output the value of $f in cnt_advanced_edit.inc, I get this:
>
>    lastname = map: (name)=(lastname), (validate)=() ...
>
>I expected a value for validate, but there is none.
>
>These are the only two modifications I made.
>
>--steve

Your last test is kind of moot.

A bit more interesting is to dig into the form object's innards:
$f -> 'fields' -> find('lastname') -> first -> value -> find('validate') -> type;

This would return 'tag'.



I just tested validate-form.lasso and it works out of the box for me. How dos it perform for you?

Here it is:

[
// A Simple Form with validated input using compund expression


// define a few validations
var('namevalidation'={return(params -> size > 0)},
        'passwordvalidation'={
                local('result'=0); // assume input is ok
                if(params -> size < 4);
                        #result = 'The password must be at least four characters';
                else(string_findregexp(params, -find='\\d') -> size == 0
                        || string_findregexp(params, -find='\\D') -> size == 0);
                        #result = 'The password should contain a mix of numbers and letters';
                else(string_findregexp(params, -find='\\s') -> size);
                        #result = 'The password should contain any spaces';
                /if;
                return(#result);
        });

// Create a new form object
var: 'form'=knop_form;

// Add text fields and a submit button
$form -> (addfield: -type='text', -name='firstname', -label='First name', -validate=$namevalidation);
$form -> (addfield: -type='text', -name='lastname', -label='Last name', -validate=$namevalidation);
$form -> (addfield: -type='text', -name='password', -label='Password', -validate=$passwordvalidation);
$form -> (addfield: -type='textarea', -name='message', -label='Message', -rows=10);
$form -> (addfield: -type='submit', -name='button_send', -value='Send message');

// load field values from form submission
$form -> loadfields;
// perform validation
$form -> validate;

// Show the form on the page
]

<form action="validate-form.lasso">
[$form -> renderform]
</form>

[if($form -> isvalid);
        'The form input is OK';
else;
        '<p style="color: red">The form has input errors<br>';
        iterate($form -> errors, var('errorfield'));
                if($errorfield -> isa('pair'));
                        $form -> getlabel($errorfield -> name) + ': ' + $errorfield -> value;
                else;
                        $form -> getlabel($errorfield) + ': The field must not be empty';
                /if;
                '<br>';
        /iterate;
        '</p>';
/if;
]
--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:joh-n@...
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday, April 6, 2009, inbox_js@... (Johan Solve) pronounced:

>At 05.42 -0700 2009-04-06, Steve Piercy - Web Site Builder wrote:
>>On Tuesday, March 24, 2009, inbox_js@... (Johan Solve) pronounced:
>>
>>>    $myform->addfield(
>>>        -type='text',
>>>        -name='answer_to_life',
>>>        ...
>>>        -validate={return(params == 42); } // true means no error
>>>    );
>>
>>I've been fumbling through some experiments with -validate, none of which have been
>successful.  I modified the demo file cfg_advanced_edit.inc, and I kept getting NULL
>returned no matter what.  Ultimately I did the following:
>>
>>    $f -> (addfield:
>>            -type='text',
>>            -name='lastname',
>>            -label=$lang_ui -> lastname,
>>            -required,
>>            -validate={return(params);},
>>            -size=40);
>>
>>When I output the value of $f in cnt_advanced_edit.inc, I get this:
>>
>>    lastname = map: (name)=(lastname), (validate)=() ...
>>
>>I expected a value for validate, but there is none.
>>
>>These are the only two modifications I made.
>
>Your last test is kind of moot.
>
>A bit more interesting is to dig into the form object's innards:
>$f -> 'fields' -> find('lastname') -> first -> value -> find('validate') -> type;
>
>This would return 'tag'.

Yeah, I was digging about in its guts, out of curiosity.  It's a good thing I didn't go into internal medicine.  :P

My intent was to find out why -validate in the demo app (not validate-form.lasso) did not do what I expected, specifically return either a true/false or 0/error code/error message.

>I just tested validate-form.lasso and it works out of the box for me. How dos it
>perform for you?

validate-form.lasso works fine.

So there is some subtle difference between the all-in-one version as opposed to the Demo which has its various parts in various files.  I suspect it is the sequence in which these parts is executed together with where I have placed the bits that causes it not to provide the error message.

/_action/act_advanced_edit.inc
/_config/cfg_advanced_edit.inc
/_content/cnt_advanced_edit.inc
/_library/lib_advanced_edit.inc

This time around I will took some snippets from validate-form.lasso, made a slight modification and put them in /_config/cfg_advanced_edit.inc

var('namevalidation'={
        local('result'=0); // assume input is ok
        if(params -> size < 1);
            #result = 'You cannot leave your last name blank.';
        else(params -> isalpha ||
            params >> '-' ||
            params >> ' '
        );
            #result = 'Last name should contain letters, spaces or hyphens only.';
        /if;
        return(#result);
}
);

    $f -> (addfield:
            -type='text',
            -name='lastname',
            -label=$lang_ui -> lastname,
            -required,
            -validate=$namevalidation,
            -size=40);

I get "Form validation failed 7101" (the default that Knop uses), and the dump of $f still shows "(validate)=()" for the field.  I'm missing something that is not obvious to me.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Jolle Carlestam-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

7 apr 2009 kl. 00.39 skrev Steve Piercy - Web Site Builder:

> /_action/act_advanced_edit.inc
> /_config/cfg_advanced_edit.inc
> /_content/cnt_advanced_edit.inc
> /_library/lib_advanced_edit.inc

The order of execution is different.

Here's the initial order
/_config/cfg_advanced_edit.inc
/_library/lib_advanced_edit.inc
/_content/cnt_advanced_edit.inc

If Knop triggers an action
/_config/cfg_advanced_edit.inc
/_action/act_advanced_edit.inc
Then if the action is successful
/_config/cfg_advanced_list.inc
/_content/cnt_advanced_list.inc
/_library/lib_advanced_list.inc
Else it will go back to the edit
/_library/lib_advanced_edit.inc
/_content/cnt_advanced_edit.inc

HDB
Jolle

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday, April 7, 2009, list@... (Jolle Carlestam) pronounced:

>7 apr 2009 kl. 00.39 skrev Steve Piercy - Web Site Builder:
>
>> /_action/act_advanced_edit.inc
>> /_config/cfg_advanced_edit.inc
>> /_content/cnt_advanced_edit.inc
>> /_library/lib_advanced_edit.inc
>
>The order of execution is different.

Yeah, that was just alphabetical sorting to indicate all the files.  My intent was to figure out where the snippets should be placed.

>Here's the initial order
>/_config/cfg_advanced_edit.inc
>/_library/lib_advanced_edit.inc
>/_content/cnt_advanced_edit.inc

From the Knop Manual, there is a diagram on p. 16.  Is the above the bottom half of the diagram (prepare output)?

>If Knop triggers an action
>/_config/cfg_advanced_edit.inc
>/_action/act_advanced_edit.inc
>Then if the action is successful
>/_config/cfg_advanced_list.inc
>/_content/cnt_advanced_list.inc  // ?swapped?
>/_library/lib_advanced_list.inc  // ?swapped?
>Else it will go back to the edit
>/_library/lib_advanced_edit.inc
>/_content/cnt_advanced_edit.inc

And is the above represented by the entire diagram (handle input/prepare output)?

Also I think you swapped the order of two files.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Jolle Carlestam-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

7 apr 2009 kl. 06.47 skrev Steve Piercy - Web Site Builder:

>
> On Tuesday, April 7, 2009, list@... (Jolle Carlestam)  
> pronounced:
>
>> 7 apr 2009 kl. 00.39 skrev Steve Piercy - Web Site Builder:
>>
>>> /_action/act_advanced_edit.inc
>>> /_config/cfg_advanced_edit.inc
>>> /_content/cnt_advanced_edit.inc
>>> /_library/lib_advanced_edit.inc
>>
>> The order of execution is different.
>
> Yeah, that was just alphabetical sorting to indicate all the files.  
> My intent was to figure out where the snippets should be placed.
>
>> Here's the initial order
>> /_config/cfg_advanced_edit.inc
>> /_library/lib_advanced_edit.inc
>> /_content/cnt_advanced_edit.inc
>
> From the Knop Manual, there is a diagram on p. 16.  Is the above the  
> bottom half of the diagram (prepare output)?

My understanding of Johans diagrams is rather limited. Sorry.

>> If Knop triggers an action
>> /_config/cfg_advanced_edit.inc
>> /_action/act_advanced_edit.inc
>> Then if the action is successful
>> /_config/cfg_advanced_list.inc
>> /_content/cnt_advanced_list.inc  // ?swapped?
>> /_library/lib_advanced_list.inc  // ?swapped?
>> Else it will go back to the edit
>> /_library/lib_advanced_edit.inc
>> /_content/cnt_advanced_edit.inc
>
> And is the above represented by the entire diagram (handle input/
> prepare output)?
>
> Also I think you swapped the order of two files.

My mistake, they are swapped. Content comes after library.

HDB
Jolle

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Johan Solve-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 07.42 +0200 2009-04-07, Jolle Carlestam wrote:

>7 apr 2009 kl. 06.47 skrev Steve Piercy - Web Site Builder:
>
>>
>>On Tuesday, April 7, 2009, list@... (Jolle Carlestam) pronounced:
>>
>>>Here's the initial order
>>>/_config/cfg_advanced_edit.inc
>>>/_library/lib_advanced_edit.inc
>>>/_content/cnt_advanced_edit.inc
>>
>>From the Knop Manual, there is a diagram on p. 16.  Is the above the bottom half of the diagram (prepare output)?
>
>My understanding of Johans diagrams is rather limited. Sorry.

Oh, not good... RFD please (Request For better Diagrams)

Anyway it's correct that cfg, lib and cnt belongs to the lower part of the diagram (below the dashed line).

>>>If Knop triggers an action
>>>/_config/cfg_advanced_edit.inc
>>>/_action/act_advanced_edit.inc
>>>Then if the action is successful
>>>/_config/cfg_advanced_list.inc
>>>/_content/cnt_advanced_list.inc  // ?swapped?
>>>/_library/lib_advanced_list.inc  // ?swapped?
>>>Else it will go back to the edit
>>>/_library/lib_advanced_edit.inc
>>>/_content/cnt_advanced_edit.inc
>>
>>And is the above represented by the entire diagram (handle input/prepare output)?

Correct. Those four types of includes (with cfg used twice if needed) make up the entire Knop application flow.



--
     Johan Sölve    [FSA Member, Lasso Partner]
     Web Application/Lasso/FileMaker Developer
     MONTANIA SOFTWARE & SOLUTIONS
http://www.montania.se   mailto:joh-n@...
 (spam-safe email address, replace '-' with 'a')

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday, April 6, 2009, Web@... (Steve Piercy - Web Site Builder) pronounced:

>This time around I will took some snippets from validate-form.lasso, made a slight
>modification and put them in /_config/cfg_advanced_edit.inc

I took another stab at it with better results.  Not perfect, but better.  I modified /_config/cfg_advanced_edit.inc

var('namevalidation'={
        local('result'=0); // assume input is ok
        if(params -> size < 1);
            #result = 'You cannot leave your last name blank.';
        else(string_findregexp(params, -find='[^a-zA-Z-_ ]'));
            #result = 'Last name should contain letters, spaces or hyphens only.';
        /if;
        return(#result);
}
);

...

    $f -> (addfield:
            -type='text',
            -name='lastname',
            -label=$lang_ui -> lastname,
            -required,
            -validate=$namevalidation,
            -size=40);

Then in /_content/cnt_advanced_edit.inc:

[/* Show the edit form */]
[if($f -> isvalid);
    'The form input is OK';
else;
    '<p style="color: red">The form has input errors<br>';
    iterate($f -> errors, var('errorfield'));
        if($errorfield -> isa('pair'));
            $f -> getlabel($errorfield -> name) + ': ' + $errorfield -> value;
        else;
            $f -> getlabel($errorfield) + ': The field must not be empty';
        /if;
        '<br>';
    /iterate;
    '</p>';
/if;
]
[$f -> renderform]

The errors display, however there is a minor problem.  "Form validation failed 7101" appears beneath the form.  I assume this is built-in to knop.lasso when ->renderform is used.  Is there a method to either suppress or alter this message?

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/

Re: Validation

by Steve Piercy :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tuesday, March 24, 2009, inbox_js@... (Johan Solve) pronounced:

>You can also extend the built-in error codes on the fly:
>
>$myform -> error_lang -> insert(-language='en', -key=9123, -value='Your input is not
>the answer to life');

I put this into the cnf file, and the error message is in there.

$f -> error_lang;

=>
map: (keys)=(), (strings)=(map: (en)=(map: (9123)=(Last name should contain letters, spaces or hyphens only.)))

However, I'm not sure how to get it to display.

>I'm not entirely sure how to use the error message you just inserted but one way would
>be like this:
>$myform -> error_msg(-error_code=9123);
>
>Maybe you can use it more elegantly but I would need to do some more research to
>figure that out.

Tried that, but it displays nothing.

--steve

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Steve Piercy               Web Site Builder               Soquel, CA
<web@...>                  <http://www.StevePiercy.com/>

--
#############################################################
This message is sent to you because you are subscribed to
the mailing list <knop@...>.
To unsubscribe, E-mail to: <knop-off@...>
Send administrative queries to  <knop-request@...>
List archive http://www.nabble.com/Knop-Framework-Discussion-f29076.html
Project homepage http://montania.se/projects/knop/
Google Code has the latest downloads at http://code.google.com/p/knop/
< Prev | 1 - 2 | Next >