On Tue, Apr 22, 2008 at 4:04 AM, Dmitrii Dimandt <[EMAIL PROTECTED]> wrote:
> Let's say that you have these fields in your form:
> - login
> - password
> - repeat_password
> - repeat_password_once_more (see the example below)
>
> You need to see if login exists, if passwords exist and that they match.
> Validation functions provided by erlyweb can't check if two fields match or
> not.
Sorry for the belated reply. I recently got back from vacation and
haven't been on top of my emails.
I think it's just as easy to do this test outside of the validation
function. This is what I've been doing:
{[Username, Password, Password1...], Errs} =
erlyweb_forms:validate(A, ["username", "password", "password1"],
fun(Field, Val) -> ... end),
Errs1 = if Password =/= Password1 ->
[password_match_error | Errs];
true ->
Errs
end,
...
Yariv
>
> I've started working on a more generic function that would allow passing
> several rules to validate a field, several functions etc.
>
> I'm not too good at programming *blush* but here's what the function does so
> far:
>
> validate(A, [{password, {'=', password_repeat}}])
> %% [] if everything is ok
> %% [[password, {not_equal, password_repeat}]]
>
> % --------------------------------
> % --------------------------------
>
>
> validate(A, [{password, [{'=', password_repeat},
> {'=', password_repeat_once_more}]
> }])
> %% [] if everything is ok
> %% [[password, [{not_equal, password_repeat},
> {not_equal, password_repeat_once_more}]]]
> % --------------------------------
> % --------------------------------
>
>
> validate(A, [{password, [{'=', password_repeat},
> {'=', password_repeat_once_more}]
> }, {login}])
>
> %% [] if everything is ok
> %% [[password, [{not_equal, password_repeat},
> {not_equal, password_repeat_once_more}]],
> [login, absent]
> ]
>
>
> What I want t achieve in the end is allowing passing such constructs as
> rules:
>
> - Functions
> validate{A, [{FieldName, module:function/2}])
> %% where function accepts A and FieldName
> - Function and value to check against
> validate(A, [{FieldName, {module:function/3, Value}}])
> %% where function accepts A, FieldName and Value
> - A slew of operators such as =, =/=, <, <=, >, >= to check against other
> fields or values
> validate(A, [{FieldName, {'=', FieldName2}}])
> validate(A, [{FieldName, {'=', "some value"}}])
>
> I'm attaching whatever I have so far to this message. It's a horrible,
> horrible mess :) So far you can only validate against to rules:
> validate(A, [{FieldName}]) %% if a field exists
> validate(A, [{FieldName, {'=', FieldName2}}]) %% if a field equals some
> other field
>
> Of course, you re not limited to the number of fields or the number of rules
> that are being passed in:
> validate(A, [
> {FieldName1},
> {FieldName2, {'=', FieldName3}},
> {FieldName4, [
> {'=', FieldName3},
> {'=', FieldName4},
> {'=', FieldName5}
> ]},
> ]
> )
>
>
> I'll be glad to hear your input on this
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"erlyweb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/erlyweb?hl=en
-~----------~----~----~----~------~----~------~--~---