More thoughts on Forge->Formo conversion

Shad Laws <shad-xpYdmXCiSuZWk0Htik3J/[email protected]> Wed, 24 Apr 2013 10:13:41 +0200
Newsgroups gmane.comp.web.gallery.devel
Message-ID <CA+z51A4YsYKWb6rLm5mBt9BLV-a6cM91wOqQLDx2tH5SaNRPag@mail.gmail.com>
--===============2809248641149674786==
Content-Type: multipart/alternative; boundary=089e012281b469d14704db16e2cf

--089e012281b469d14704db16e2cf
Content-Type: text/plain; charset=UTF-8

Hey everyone,

I'm working on getting acquainted with Formo a bit more, and it seems like
the default, expected actions of Formo is a bit different than how we were
using Forge in Gallery 3.0.x.

Before, we usually (but not always) had a separate controller action for
showing a form vs. validating a form (e.g. action_edit() and
action_save()).  Also, it was common to have a third function generate the
form for us, so we ended handling the form in three places.

It seems that the default, expected behavior of Formo is to do this in one
place with one action.  It's smart enough to figure out if we have post
data or not, and therefore if we are in "edit" or "save" mode (following
the example).  An example:

public function action_edit() {
  $form = Formo::form(...)
          ->....; // build form, load with default values.

  if ($form->load()->validate()) {
    // load() gets the values from post/files and fills the values,
    // then validate() checks stuff and does nothing if the form isn't
    // yet sent (nothing loaded) or adds errors if it was.

    // Do some more stuff... then:
    Message::success(t("Done!"));
    // And/or:
    $this->redirect("somewhere/else");
  }

  $view = .....;
  $view->form = $form;

  $this->response->body($view);
}

I can overload a couple Formo classes to ensure that each form contains and
validates our csrf, similar to what we did with Forge.

Does this seem like a reasonable approach?  Is there some other reason why
we intentionally divided these up into multiple actions before?

Take care,
Shad

--089e012281b469d14704db16e2cf
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hey everyone,<div><br></div><div style>I&#39;m working on =
getting acquainted with Formo a bit more, and it seems like the default, ex=
pected actions of Formo is a bit different than how we were using Forge in =
Gallery 3.0.x.</div>

<div style><br></div><div style>Before, we usually (but not always) had a s=
eparate controller action for showing a form vs. validating a form (e.g. ac=
tion_edit() and action_save()). =C2=A0Also, it was common to have a third f=
unction generate the form for us, so we ended handling the form in three pl=
aces.</div>

<div style><br></div><div style>It seems that the default, expected behavio=
r of Formo is to do this in one place with one action. =C2=A0It&#39;s smart=
 enough to figure out if we have post data or not, and therefore if we are =
in &quot;edit&quot; or &quot;save&quot; mode (following the example). =C2=
=A0An example:</div>

<div style><br></div><div style><font face=3D"courier new, monospace">publi=
c function action_edit() {</font></div><div style><font face=3D"courier new=
, monospace">=C2=A0 $form =3D Formo::form(...)</font></div><div style><font=
 face=3D"courier new, monospace">=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 -&gt;..=
..; // build form, load with default values.</font></div>

<div style><font face=3D"courier new, monospace"><br></font></div><div styl=
e><font face=3D"courier new, monospace">=C2=A0 if ($form-&gt;load()-&gt;val=
idate()) {</font></div><div style><font face=3D"courier new, monospace">=C2=
=A0 =C2=A0 // load() gets the values from post/files and fills the values,<=
/font></div>

<div style><font face=3D"courier new, monospace">=C2=A0 =C2=A0 // then vali=
date() checks stuff and does nothing if the form isn&#39;t</font></div><div=
 style><font face=3D"courier new, monospace">=C2=A0 =C2=A0 // yet sent (not=
hing loaded) or adds errors if it was.</font></div>

<div style><font face=3D"courier new, monospace"><br></font></div><div styl=
e><font face=3D"courier new, monospace">=C2=A0 =C2=A0 // Do some more stuff=
... then:</font></div><div style><font face=3D"courier new, monospace">=C2=
=A0 =C2=A0=C2=A0Message::success(t(&quot;Done!&quot;));</font></div>

<div style><font face=3D"courier new, monospace">=C2=A0 =C2=A0 // And/or:</=
font></div><div style><font face=3D"courier new, monospace">=C2=A0 =C2=A0 $=
this-&gt;redirect(&quot;somewhere/else&quot;);</font></div><div style><font=
 face=3D"courier new, monospace">=C2=A0 }</font></div>

<div style><font face=3D"courier new, monospace">=C2=A0=C2=A0</font></div><=
div style><font face=3D"courier new, monospace">=C2=A0 $view =3D .....;</fo=
nt></div><div style><font face=3D"courier new, monospace">=C2=A0 $view-&gt;=
form =3D $form;</font></div>

<div style><font face=3D"courier new, monospace"><br></font></div><div styl=
e><font face=3D"courier new, monospace">=C2=A0 $this-&gt;response-&gt;body(=
$view);</font></div><div style><font face=3D"courier new, monospace">}</fon=
t></div>

<div style><br></div><div style>I can overload a couple Formo classes to en=
sure that each form contains and validates our csrf, similar to what we did=
 with Forge.<br></div><div style><br></div><div style>Does this seem like a=
 reasonable approach? =C2=A0Is there some other reason why we intentionally=
 divided these up into multiple actions before?</div>

<div style><br></div><div style>Take care,</div><div style>Shad</div></div>

--089e012281b469d14704db16e2cf--


--===============2809248641149674786==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
--===============2809248641149674786==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

__[ g a l l e r y - d e v e l ]_________________________

[ list info/archive --> http://gallery.sf.net/lists.php ]
[ gallery info/FAQ/download --> http://gallery.sf.net ]
--===============2809248641149674786==--