[html-formfu] Modifying a form field.

Octavian Rasnita orasnita at gmail.com
Thu Apr 2 07:14:04 BST 2009


From: Leanan Sidhe =

  I have heard that TIMTOWTDI, but the only suggestions I've seen were in r=
egards to password fields and using DBIx::Class::DigestColumns.  I need to =
do some mathematical conversions on columns before the data is put into the=
 database.  I'm trying to do it this way:



    my $elements_to_convert =3D $form->get_all_elements({ type =3D> 'Text'}=
);

    foreach my $element (@{$elements_to_convert}) {
      if ($element->attributes->{'class'} =3D~ /I-want-to-convert-this/){
        my $nested_name =3D $element->nested_name;
        my $field_value =3D $form->param_value($nested_name);
        $element->default(($field_value * $conversion));
      }
    }

  However, nothing is working.  I've tried $element->default($my_new_value)=
, $form->default_values($nested_name =3D> $my_new_value), $form->default_va=
lues({$nested_name =3D> $my_new_value}) and $form->add_valid($nested_name, =
$my_new_value}).  None of these seemed to work.

  Is add_valid only for adding new fields?  The doc says "The provided valu=
e replaces any current value for the named field." which suggests to me tha=
t if I have a field foo, $form->add_valid(foo, $new_value) should work.  Bu=
t then I saw this in HTML::FormFu::Model::DBIC: "add_valid works for fieldn=
ames that don't exist in the form." Which suggest that it only works to add=
 new valid fields.  I'm a little confused by this.

  Ideas?  Thanks!


  I was also very confused about that part of the POD documentation and I f=
ound that the most easy solution is to use:



  $c->req->param('password', sha1_hex($c->req->param('password')));
  $form->process;


  With other words, change the value of $c->req->param('field_name') and no=
t the value of an element in $form.

  Then do $form->process.



  This way isn't recommended because this type of change should be done in =
the DBIC class and not in the controller, for beeing able for example to do=
 the same thing from an external program that has nothing to do with the Ca=
talyst framework, but I don't know how to do this in the class file, becaus=
e I haven't seen any example of doing this.

  Maybe DBIx::Class::DigestColumns can be extended to accept other type of =
changes than just digests...



  Octavian


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/html-formfu/attachments/20090402/cc=
3f96f0/attachment.htm


More information about the HTML-FormFu mailing list