[Bese-devel] Forms validation and a possible patch.

Pupeno pupeno at pupeno.com
Wed Jun 21 12:35:10 UTC 2006


Hello,
I am writting the code to validate a form, taking from forms.lisp (the
example) I wrote the following (which generates a more user friendly set
of messages):

(flet ((push-message-unless-valid (field name)
           (multiple-value-bind (validp failed-validators)
               (validp field)
             (unless validp
	       (dolist (failed-validator failed-validators)
		 (push (list "error" 
			     (format nil "~A ~A" name 
				     (cond 
				       ((typep failed-validator 'not-empty-validator)
					"should not be empty.")
				       ((typep failed-validator 'length-validator)
					(format nil "is too short. It should be at least ~a letters
long." (min-length failed-validator)))
				       (t "is not valid."))))
		       (messages form)))))))
    (push-message-unless-valid (account-name form) "Your name")
    (push-message-unless-valid (account-email form) "Your email")
    (push-message-unless-valid (account-password form) "Your password")

Basically the difference is that I don't print the class of the
validator that failed but I dispatch on it generating a friendly message
(the cond there).
Is that a good way to do it ? Is there a better ?
Now, to be able to generate the message "Your password is too short. It
should be at least 6 letters long." I needed to export min-length from
ucw, would you consider that a good thing ? I also exported max-length
while I was at it.
The patch is attached.
-- 
Pupeno <pupeno at pupeno.com> http://pupeno.com

PS: Note that I am working with the latest box and not the latest...
just to avoid problems. But it shouldn't be a problem for this patch.
-------------- next part --------------

New patches:

[Export min and max -length for the length-validator.
Jos? Pablo Ezequiel "Pupeno" Fern?ndez Silva <pupeno at pupeno.com>**20060621122848] {
hunk ./src/packages.lisp 186
+   #:min-length
+   #:max-length
}

Context:

[(setf container.current-component) returns t when the set actually happened
attila.lendvai at gmail.com**20060606195958] 
[Fix dynamic forms example delete
attila.lendvai at gmail.com**20060604201256] 
[Split ucw.css and examples.css
attila.lendvai at gmail.com**20060604200705] 
[Added child-components to container, WARNING: small api change
attila.lendvai at gmail.com**20060604185229
 
 In the process renamed the :pred kayword argument to :predicate
] 
[Doc/comment fixes
attila.lendvai at gmail.com**20060604185138] 
[Add typecheck to s-c s-v-u-c and also set the parent slot
attila.lendvai at gmail.com**20060604172617] 
[Export get-paremeter and map-parameters
Marco Baringer <mb at bese.it>**20060604171847] 
[When adding the ucw-form-field-invalid class remeber to remove the ucw-form-field-valid class (Patch by: Marijn Haverbeke <marijnh at gmail.com>)
Marco Baringer <mb at bese.it>**20060604171146] 
[- secure-application#exit-user is broken due to removal of find-entry-point.
evrim at core.gen.tr**20060531115550] 
[Silly typos in previous patch
Marco Baringer <mb at bese.it>**20060604141410] 
[Added :class attributes to all the form elements
Marco Baringer <mb at bese.it>**20060604140146] 
[Allow for component-slot definition with :component nil
Nathan Bird <nathan at acceleration.net>**20060508155758
 This patch changes the way the component-class.component-sltos 
 list is built. It should now be in the same order as the class-slots
 which is hopefully the same order they were defined in.
 
 Additionally (the bigger reason) is so that slots that were 
 declared with ':component nil' are marked as being component-slots
 but are left unbound.
] 
[Bind swank::*sldb-quit-restart* to 'fail-miserably
Nathan Bird <nathan at acceleration.net>**20060531193531
 
 Now when the slime debug buffer pops up while handling a web request,
 'q' (sldb-quit) will cause the 'fail-miserably restart to be invoked.
] 
[fixing logging message typo
Nathan Bird <nathan at acceleration.net>**20060531155026] 
[made the remove component :after be correctly specialized
Russ Tyndall <russ at acceleration.net>**20060529222215] 
[added pass through for optional args in read client string
Russ Tyndall <russ at acceleration.net>**20060525223940] 
[made it correctly out put human number strings rather than lisp number strings (aka no more 1.23d0)
Russ Tyndall <russ at acceleration.net>**20060517164149] 
[provide #'meta-refresh
Nathan Bird <nathan at acceleration.net>**20060529215502
 Cause a meta-refresh (a freshly got (GET) url) at this point.
 This is useful in order to have a GET url after a form POST's
 actions have completed running. The user can then refresh to his
 heart's content.
] 
[Adding child-components export
Nathan Bird <nathan at acceleration.net>**20060508161431] 
[Add a child-components function
Nathan Bird <nathan at acceleration.net>**20060508160149] 
[Export ucw::get-header
Marco Baringer <mb at bese.it>**20060530233436] 
[Added render-option specialized on nil
attila.lendvai at gmail.com**20060530213435] 
[Don't specialize slot-value-using-class on the value parameter
Marco Baringer <mb at bese.it>**20060530105600] 
[write-uri-sans-query needs to deal with 'special' characters in the query-part
Marco Baringer <mb at bese.it>**20060529182043] 
[Added logging statements which report the action being evaluated.
Marco Baringer <mb at bese.it>**20060529080637] 
[Add "_" prefix to all ucw defined query parameters.
Marco Baringer <mb at bese.it>**20060529072846
 
 This helps aliviate (but does not completly remove) the probablitily
 of a ucw defined parameter conflicting with a user defined
 parameter. I'll admit that the odds of one of ucw's randomly defined
 parameter names being the same as a user defined parameter name are
 slim, but when it does happen it's a
 once-every-1000-totally-unreproducable-100%untractable error :(
] 
[Implement radio-button widget
Marco Baringer <mb at bese.it>**20060529072632] 
[Tiny doc fix
attila.lendvai at gmail.com**20060525225601] 
[Added remove-component to container
attila.lendvai at gmail.com**20060523154055] 
[Set arnesi:*warn-undefined* to T in the start.lisp script
Marco Baringer <mb at bese.it>**20060526192721] 
[Fix erroneous evaluation bug in ucw-tags.lisp
Marco Baringer <mb at bese.it>**20060526192234
 
 the code which checked for the precesne of an action parameter in a
 <ucw:form was calling the action at runtime, instead of checking for
 the precense of an action parameter at compile time.
] 
[Added (setf container.current-component)
attila.lendvai at gmail.com**20060519175132] 
[POST is post in the standard
attila.lendvai at gmail.com**20060518220542] 
[Make per-application.js matching regex strict
attila.lendvai at gmail.com**20060518214310] 
[fixes several buglike things in forms:
cjstuij at gmail.com**20060516123951
 
 - the javascript number validator now accepts fractions
 - the javascript integer validator now disallows floating points
 - fixed the email validator
 - allows <ucw:month-select to have other attributes than just accessor
 - in month-select changed Dicember to December
 
] 
[Changed widget-component's render from :wrapping to :wrap-around
attila.lendvai at gmail.com**20060516144443] 
[Move binding of *current-component* into render :wrap-around
attila.lendvai at gmail.com**20060516112354] 
[Tiny doc fix
attila.lendvai at gmail.com**20060511145417] 
[merge the `:ucw.default' and `:ucw.config' systems into the `:ucw' one
Luca Capello <luca at pca.it>**20060514233614
 
 To simplify things, the two systems used by bin/ucwctl are merged into
 the general `:ucw' one.  As a side-effect, etc/start.lisp now loads
 the `*ucw-config-file*' when present or set the `*ucw-systems*' and
 `*ucw-applications*' variables.
 
   http://common-lisp.net/pipermail/bese-devel/2006-May/002122.html
] 
[Export ucw:is-an-integer-validator.
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060514232653] 
[Add message slot to validator class to contain an error message.
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060514232631] 
[switch from bare-bones dojo to ajax edition. To fix dependency errors where ucw expects the dojo.html namespace or whatever you want to call it to be present.
cjstuij at gmail.com**20060510220528] 
[Read-from-client-string
Nathan Bird <nathan at acceleration.net>**20060430215547
 Useful for reading data from questionable origins where *read-eval* needs to be false.
] 
[Indentation fixup in tabbed-pane.lisp
Marco Baringer <mb at bese.it>**20060509102104] 
[Minor refactoring in container.lisp
Marco Baringer <mb at bese.it>**20060509102050] 
[Mention the difference between (setf application.dispathers) and (setf (slot-value app 'dispatchers)) in the docstring
Marco Baringer <mb at bese.it>**20060509101051] 
[Add a <ucw:simple-submit and <ucw:simple-form that do not require javascript.
Drew Crampsie <drewc at tech.coop>**20060506233602
 
 <ucw:simple-submit uses a BUTTON tag to render a submit button that does not require javascript
 
 To make this happen, i added a method to find-action that operates on a list, 
 grabbing the car and using it as the action id. When a form is submitted with an extra action parameter, 
 the last one submitted (first in the list) is taken to be the action-id.
 
 This allows forms without javascript!! SIMPLE-SUBMIT will work in the standard UCW:FORM, 
 SIMPLE-FORM is a form without the JS cruft, but will not work with standard <UCW:* submit buttons.
 
 
 
] 
[Fix serve-file
attila.lendvai at gmail.com**20060509132443] 
[Added serve-sequence next to serve file with a defserve macrolet
attila.lendvai at gmail.com**20060508220833] 
[Resolve conflicts with "Don't send headers set to NIL (especially Content-Length:) in response."
attila.lendvai at gmail.com**20060508203035] 
[Add dojo.js to standard-window to avoid user surprises
attila.lendvai at gmail.com**20060508202328] 
[Ensure in shared-initialize of standard-application that the required dispatchers exists
attila.lendvai at gmail.com**20060508202029
 
 action dispatcher and a parenscript-dispatcher is crucial for UCW to function properly.
 To make sure things work fine in the normal situations add them in shared-initialize.
 For full control one can still use the application.dispatchers accessor...
] 
[Use context.cookie-value to acces session cookie, also rename the cookie constant to +ucw-session-cookie-name+
attila.lendvai at gmail.com**20060508190228] 
[Added parenscript-dispatcher
attila.lendvai at gmail.com**20060508185842
 
 It lazily compiles a parenscript file at the first request and tehn serves it.
] 
[Added a per-application parenscript file
attila.lendvai at gmail.com**20060506225010] 
[Added encoding method to response
attila.lendvai at gmail.com**20060506174248] 
[Added context.cookies and context.cookie-value
attila.lendvai at gmail.com**20060505223724] 
[Use widget-component.css-* accessors when rendering, so that it can be overridden
attila.lendvai at gmail.com**20060504151409] 
[Do not render the ol/li elements when the container has only one member
attila.lendvai at gmail.com**20060504120248] 
[Resolve conflicts
attila.lendvai at gmail.com**20060423184525] 
[Added tabindex support for form-fields
attila.lendvai at gmail.com**20060414130400] 
[Docfix for net-telent-date dependency.
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060504233324] 
[INCOMPATIBLE CHANGE: add NET-TELENT-DATE dependency, send out Date: header, make SERVE-FILE cache-friendly (use Date:, Last-Modified:, Expires: and If-Modified-Since: headers).
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060503013844] 
[Don't send headers set to NIL (especially Content-Length:) in response.
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060503013648] 
[New function (delete-header message header-name).
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060503011904] 
[Don't send body if HTTP method is HEAD.
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060502222010] 
[Save HTTP method of request as string.
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060502221955] 
[Initform for (request response).
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060502221939] 
[Include in httpd response a request associated with it.
Maciek Pasternacki <maciekp at japhy.fnord.org>**20060502221158] 
[changed docs to get up to date and add some info
cjstuij at gmail.com**20060503094055] 
[Added send-redirect function.
Marco Baringer <mb at bese.it>**20060501154250
 
 send-redirect does what redirect-component's render method did but
 it's usable from a simple-dispatcher (or anywhere else we don't have
 ucw's component context machinery).
] 
[Use dolist*, not dolist, in tabbed-pane's render method.
Marco Baringer <mb at bese.it>**20060501135314] 
[Using (when (whatever) T) is weird, use (whatever) instead
Marco Baringer <mb at bese.it>**20060501135000] 
[Minor indentation/whitespace fixups in src/components/form.lisp
Marco Baringer <mb at bese.it>**20060501134849] 
[make-with-dummy-request-nicer
cjstuij at gmail.com**20060501001756] 
[tabbed-pane-makeover - tabbed panes are now wrapped in divs in stead of a table, for more design flexibility. Is no longer tied to a tal file.
cjstuij at gmail.com**20060430233920] 
[Removing integer-range-validator, use number-range-validator instead.
Nathan Bird <nathan at acceleration.net>**20060428165829] 
[the value of a number-field should be nil, not 0, if nothing was entered.
Nathan Bird <nathan at acceleration.net>**20060428164949] 
[bin/ucwctl: allow a custom ucwctl.conf via -u|--ucwctl-file
Luca Capello <luca at pca.it>**20060501110031
 
 This adds the possibility to specify a different ucwctl.conf file
 instead of the default /etc/ucw/ucwctl.conf.  Moreover, by default
 ucwctl now reads ~/.ucw/ucwctl.conf it it exists, overriding the
 values in the general /etc/ucw/ucwctl.conf, and the same happens if
 the ucwctl.conf is specified via the command line option.  All command
 line options override the values present in any ucwctl.conf files.
 The order is the following:
 
   1) /etc/ucw/ucwctl.conf (if it exists)
   2) ~/.ucw/ucwctl.conf (if it exists)
   3) -u|--ucwctl-file (if specified, exit if it cannot be read)
   4) command line options
 
 A deeper discussion is available at:
 
   http://common-lisp.net/pipermail/bese-devel/2006-April/001932.html
   http://common-lisp.net/pipermail/bese-devel/2006-April/001961.html
] 
[In the phone and email validators instead of defining a new slot we just use the :default-initargs class option
Marco Baringer <mb at bese.it>**20060428103114] 
[Adding documentation to form.lisp
Nathan Bird <nathan at acceleration.net>**20060428023256] 
[Rearranging file contents to reduce style-warnings
Nathan Bird <nathan at acceleration.net>**20060428022511] 
[Implementing value-validators
Nathan Bird <nathan at acceleration.net>**20060428020403
 Value-validators are a category of validators that are only applied if there 
 is actually a value. This was done to provide a more systematic scheme since
 there were several different ways it was being handled previously.
 Javascript validation in this patch is untested.
] 
[Expanded the forms example to include a number-field and number-range-validated field.
Nathan Bird <nathan at acceleration.net>**20060428014551] 
[added a standard regular exprexpression validator then made e-mail-validator use it.  E-mail-validator IS NO LONGER INVALID IF EMPTY. Adde d an international phonenumber validator
russ at acceleration.net**20060425154947] 
[added regex exports
russ at acceleration.net**20060424225714] 
[Comment fixup
Nathan Bird <nathan at acceleration.net>**20060427173259] 
[Added missing id param that got lost in my <ucw:form changes
attila.lendvai at gmail.com**20060424150549] 
[TAG 2006-04-25
Marco Baringer <mb at bese.it>**20060425145623] 
Patch bundle hash:
db9f4853787de8751cbaaa41c021b24792ef4312
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
URL: <https://mailman.common-lisp.net/pipermail/bese-devel/attachments/20060621/cb6f85b0/attachment.sig>


More information about the bese-devel mailing list