[Catalyst] Question about Catalyst::Controller::FormBuilder

Balaji Srinivasan balajione at gmail.com
Sun May 13 18:43:31 GMT 2007


Rather than the two approaches above, I think a better one was to add a new
validation type to the FormBuilder VALIDATE array.
$CGI::FormBuilder::Field::VALIDATE{FOOFIELD} =3D '/^[^,"]{6,40}$/';

Now in all my forms, i just set the validate field to FOOFIELD.
This works great for me. It avoide me having to write my own validation code
and also avoids the need to add the regex to each form.
Balaji

On 4/30/07, Christopher H. Laco <claco at chrislaco.com> wrote:
>
> Balaji Srinivasan wrote:
> > Hi There
> > I am using Catalyst::Controller::FormBuilder to create my forms. Its
> > working
> > great for me except for this one issue:
> > I would like to specify a field that has a regexp that has a comma in
> it.
> > For example:
> >
> >
> > sub doStuff : Path('/doStuff) Form('/doStuff') {
> >
> > .....
> > }
> >
> > My doStuff.fb file has the following field
> >
> > fields:
> >    username:
> >        label: Username
> >        size: 40
> >        validate: /^[^,"]{6,40}$/
> >
> > ie I want the username field to contain 6-40 characters without any
> single
> > or double quotes.
> > Unfortunately the validation code for this on the javascript side turns
> > into:
> >
> >    var username =3D form.elements['username'].value;
> >    if (username =3D=3D null || (username !=3D '/^[^'"]{6' && username !=
=3D
> > '40}+$/')) {
> >        alertstr +=3D 'Username should be between 6 and 40 characters
> > and should not contain single-quotes (\') or double-quotes (")\n';
> >        invalid++;
> >    }
> >
> >
> > ie. The value is split at the , sign.
> > This looks like it would be a fairly common problem. Any workaround for
> > this?
> > Thanks
> > Balaji
> >
>
>
> This ia s know, unfixed bug. You options are:
>
> a) manually add the regex to the form in controller code
> b) use FB only to render forms, and use something else to validate forms
>
> I opted for b) when I ran into this problem.
>
> -=3DChris
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20070513/38b44=
f62/attachment.htm


More information about the Catalyst mailing list