Ohh, by the way, if you need to write html into the form, you can also do it without any TT view file. <br><br>With Formhandler it is very simple, just use the field of type &#39;Display&#39;, for example:<br>    has_field &#39;display0&#39; =&gt; (<br>
         type =&gt; &#39;Display&#39;,<br>         html =&gt; &#39;<br>&lt;div class=&quot;clear&quot;&gt;&lt;h1 class=&quot;formtitle&quot;&gt;Your Personal Data&lt;/h1&gt;&lt;/div&gt;<br>&lt;script&gt;foo bar baz&lt;/script&gt;<br>
&#39;       <br>         );<br><br><br><br><br><div class="gmail_quote">On Mon, Sep 20, 2010 at 8:09 PM, Hernan Lopes <span dir="ltr">&lt;<a href="mailto:hernanlopes@gmail.com">hernanlopes@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">perl Catalyst Forms with Formhandler and Thickbox:<br><br>You know you dont always need a template.tt2 file... this is useful with ajax (especially with thickbox) so you can pass a scalar as template, so you end up with:<br>

 $c-&gt;stash( template =&gt; $form-&gt;render, current_view =&gt; &#39;Ajax&#39;, );<br>1. You could create an Ajax view.<br>2. Or you can set body content directly. <br>This way you skip creating TT files for forms and render them directly into the $c-&gt;res-&gt;body or $c-&gt;stash( template =&gt; \&#39;foo baz&#39;)<br>

If you use something like thickbox, you can render any $form directly into a modal. <br>Its very handy!<br><br>For example:<br><br><br>__PACKAGE__-&gt;config(<br>    action =&gt; {<br>        edit =&gt; { Chained =&gt; &#39;base&#39;, Args =&gt; 1, },<br>

    },<br>);<br><br>sub base : Chained(&#39;/&#39;) PathPart(&#39;foobar&#39;) CaptureArgs(0) {}<br><br>sub edit :Action {<br>  my ( $self, $c, $foobar_id ) = @_;<br>  my $form = HTML::FormHandler-&gt;new(<br>    schema =&gt; &#39;DBSchema::Foo&#39;,<br>

    params =&gt; $c-&gt;req-&gt;params,<br>    field_list =&gt; $self-&gt;form_fields($c),<br>      );<br>    if( $c-&gt;req-&gt;method eq &#39;POST&#39; &amp;&amp; $form-&gt;process() ) {<br>      ...<br>      } else {<br>

  #OPTION 1 (create an Ajax View and create a wrapper for it. Then render the form into stash template var):<br>        $c-&gt;stash(<br>          template =&gt; \$form-&gt;render,<br>          current_view =&gt; &#39;Ajax&#39;,<br>

          );<br>  #OPTION 2 (set your content type and charset and render the form into the body, needs no view/TT files):<br>        $c-&gt;res-&gt;content_type(&#39;text/html charset=utf-8&#39;);<br>        $c-&gt;res-&gt;body($form-&gt;render);<br>

        }<br>  }<br><br><br><br><br>sub form_fields {<br>    return [<br>        field_one =&gt; {<br>        type =&gt; &#39;Text&#39;,<br>        label =&gt; &#39;...&#39;,<br>        css_class =&gt; &#39;...&#39;,<br>
        maxlength =&gt; 160,<br>
        required =&gt; 1,<br>        required_message =&gt; &#39;Required Text&#39;,<br>        },<br>        submit =&gt; {<br>          type =&gt; &#39;Submit&#39;,<br>          value =&gt; &#39;Save&#39;,<br>          css_class =&gt; &#39;...&#39;,<br>

         },<br>    ];<br>}<br><br><br><br>and DRY on edit &amp; update unless necessary... <br>1. If there is an argument its &quot;update?&quot; <br>2. Else, when it has no args then its &quot;edit/new&quot; ? <br><br>use your foregin_key_id and $form(&#39;foregin_key_id&#39;)-&gt;value = &#39;...&#39; to set it , then formhandler will know whether to update or create a new entry.<br>

<br>Take care,<br><font color="#888888">hernan</font><div><div></div><div class="h5"><br><br><br><br><br><br><div class="gmail_quote">On Mon, Sep 20, 2010 at 6:48 PM, E R <span dir="ltr">&lt;<a href="mailto:pc88mxer@gmail.com" target="_blank">pc88mxer@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
I am curious what everyone thinks as being the best practices for<br>
handling forms in Catalyst. Are there any Catalyst applications you<br>
have run across which are good examples of how to use Catalyst&#39;s<br>
features to handle forms?<br>
<br>
To illustrate what I am getting at, below is typical Rails (v2)<br>
controller code which implements updating the attributes of an object:<br>
<br>
   def edit<br>
      @book = Book.find(params[:id])<br>
      @subjects = Subject.find(:all)<br>
   end<br>
   def update<br>
      @book = Book.find(params[:id])<br>
      if @book.update_attributes(params[:book])<br>
         flash[:notice] = &#39;Book successfully updated.&#39;<br>
         redirect_to :action =&gt; &#39;show&#39;, :id =&gt; @book<br>
      else<br>
         @subjects = Subject.find(:all)<br>
         render :action =&gt; &#39;edit&#39;<br>
      end<br>
   end<br>
<br>
In Catalyst, this would be appear something like (and please correct<br>
me if I have made any errors here):<br>
<br>
sub edit  :Args(1) {<br>
  my ($self, $c, $id) = @_;<br>
  ... set up $c-&gt;stash for template &#39;edit&#39; ...<br>
  # no need to set $c-&gt;stash-&gt;{template} - will be set from the current action<br>
}<br>
<br>
sub update :Args(1) {<br>
  my ($self, $c, $id) = @_;<br>
  ...process form...<br>
  if (form is valid) {<br>
    ...perform updates...<br>
    $c-&gt;flash-&gt;{notice} = &#39;Book successfully updated.&#39;;<br>
    $c-&gt;res-&gt;redirect(&#39;show&#39;, $id);<br>
  } else {<br>
    ... set up $c-&gt;stash for &#39;edit&#39; template ...<br>
    $c-&gt;stash-&gt;{template} = &#39;edit&#39;;<br>
  }<br>
}<br>
<br>
Any comments on this architecture? Is there a better way? My main problems are:<br>
<br>
1. The code ... set up $c-&gt;stash for &#39;edit&#39; template ... is duplicated<br>
in both edit and update (which is also true for the Rails code).<br>
<br>
2. Having the template name defaulted from the current action is nice,<br>
but that means we have to explicitly set it in the update method. Is<br>
it better to always explicitly set the template name in a controller<br>
method? Then update could perform a $c-&gt;detach(&#39;edit&#39;, $id) or would<br>
you use $c-&gt;go(&#39;edit&#39;, $id)?<br>
<br>
Thanks,<br>
ER<br>
<br>
_______________________________________________<br>
List: <a href="mailto:Catalyst@lists.scsys.co.uk" target="_blank">Catalyst@lists.scsys.co.uk</a><br>
Listinfo: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst" target="_blank">http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst</a><br>
Searchable archive: <a href="http://www.mail-archive.com/catalyst@lists.scsys.co.uk/" target="_blank">http://www.mail-archive.com/catalyst@lists.scsys.co.uk/</a><br>
Dev site: <a href="http://dev.catalyst.perl.org/" target="_blank">http://dev.catalyst.perl.org/</a><br>
</blockquote></div><br>
</div></div></blockquote></div><br>