[html-formfu] File element issues

Diego Kuperman diego at freekeylabs.com
Wed Dec 26 10:29:07 GMT 2007


Hi!

I'm having some issues when handling file elements, I'm using FormFu 
from Catalyst:

* If I put the constraint "required" on a file field then 
form->submitted_and_valid is always false, but the form->param and 
$c->req->upload gave the file element ok!.
My yml description looks like this (I stripped aditional fields)

indicator: submit
auto_fieldset: { legend : 'Song data' }
elements:

     - type: File
       name: songfile
       label: MP3/OGG File
       constraints:
         - Required

     - type: Submit
       name: submit
       value: Save song



* When I access to the file at the controller, taking the constraint out 
or not, it is ok, but I can't use all the methods available for 
Catalyst::Request:Upload objects.
I looked on the source and figured out that what I get is a FormFu 
object that wrap the original and pass to it the messages, so it is 
possible to add more gateway methods into 
/HTML/FormFu/QueryType/Catalyst.pm to get access to all the methods 
provided by the wrapped object:

=== lib/HTML/FormFu/QueryType/Catalyst.pm
==================================================================
--- lib/HTML/FormFu/QueryType/Catalyst.pm       (revision 2054)
+++ lib/HTML/FormFu/QueryType/Catalyst.pm       (local)
@@ -65,4 +65,40 @@
      return $self->_param->slurp;
  }

+sub basename {
+    my ($self) = @_;
+
+    return $self->_param->basename;
+}
+
+sub copy_to {
+    my ($self) = @_;
+
+    return $self->_param->copy_to;
+}
+
+sub link_to {
+    my ($self) = @_;
+
+    return $self->_param->link_to;
+}
+
+sub size {
+    my ($self) = @_;
+
+    return $self->_param->size;
+}
+
+sub tempname {
+    my ($self) = @_;
+
+    return $self->_param->tempname;
+}
+
+sub type {
+    my ($self) = @_;
+
+    return $self->_param->type;
+}
+

I had tried it and works for me, I don't know if it is the best way or 
the best place... but if it is ok, I can push it to the svn.

I'm very new to FormFu, I'm doubting why is there the need to wrap the 
Upload at all... Why $form->param('uploaded_file_field') doesn't return 
just the C::R::Upload object when running under Catalyst?... or to have 
some other way to access the "original" object like:

sub get_upload_object {
     return $_[0]->_param;
}

Cheers,
Diego




More information about the HTML-FormFu mailing list