Forum OpenACS Q&A: How to use the -validate block for extending forms

Request notifications

I'm having trouble getting the -validation block to work in a form.

I've been trying to add some additional fields to the admin screen for registering a user. i.e. I'm editing acs-subsite/lib/user-new.tcl

Here's the code fragment:
# Pre-generate user_id for double-click protection
set user_id [db_nextval acs_object_id_seq]

ad_form -name register -export {next_url user_id return_url} -form [auth::get_registration_form_elements]

# new stuff
ad_form -extend -name register -form {
                {label "Mobile Number"}
                {label "House Name/Number"}
                {label "Street Name"}
                {label "City/Town"}
                {label "County"}
                {label "Post Code"}
                {label "Home/Evening Phone"}
                {label "Work/Daytime Phone"}
} -validate {
                "Wrong length"

Although I know its parsing the validation block ok, when I enter the form it just allows the msisdn value through anyway... (hence I've set it to 0 at the moment to force it to fail)

Am I doing something wrong here? can you not use -validate on form extensions? To the best of my knowledge I've followed the documentation?

Any help gratefully received.


Posted by Randy O'Meara on
Try placing the entire block on one line.

{msisdn {0} "Wrong length"}

Posted by Simon at TCB on
nope, still no joy.

I'm suspicious that it might be something to do with the form definition that is returned by


but i can't find anything... hmmm.. what a nusiance...

Posted by Simon at TCB on
sorted it. my mistake I misunderstood the documentation.

there was another ad_form -extend lower down the page, and the -validate block is an 'action' block that must appear after all those...

thanks anyway, sorry for any time wasted

Posted by Don Baccus on
That's a bug, the attempt to extend the form after the appearance of a validation block should trigger an error.  I added the validation block feature after having added form extension as a feature and must've forgotten to add the check.

Please file a bug report ...