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

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 {
        {msisdn:text
                {label "Mobile Number"}
        }
        {house_name_number:text
                {label "House Name/Number"}
        }
        {street_name:text
                {label "Street Name"}
        }
        {city_town:text
                {label "City/Town"}
        }
        {county:text
                {label "County"}
        }
        {postcode:text
                {label "Post Code"}
        }
        {home_phone:text,optional
                {label "Home/Evening Phone"}
        }
        {work_phone:text,optional
                {label "Work/Daytime Phone"}
        }
} -validate {
        {msisdn
                {0}
                "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.

Simon

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

{msisdn {0} "Wrong length"}

Collapse
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

auth::get_registration_form_elements

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

Collapse
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

Collapse
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 ...