[Zope] ZPT, DTML, SQL and Forms
Colin Fox
cfox@crystalcherry.com
26 Mar 2002 12:43:18 -0800
--=-seoVwI2Gu2ZxVt3qDund
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
On Tue, 2002-03-26 at 08:29, Jeff Peterson wrote:
<snip>
>=20
> it makes more sense to me to call it in your template:
>=20
>=20
> Page Template
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
> (might have to massage the param/value part if it's needed; get it from
> request or some other way)
>=20
> <table tal:define=3D"data python:here.your_sql([param=3Dvalue])">
> <tr tal:repeat=3D"items data">
> <td><LABEL for=3D"firstname">First name: </LABEL></td>
> <td><INPUT type=3D"text" name=3D"first_name" value=3D""
> tal:attributes=3D"value items/colname"
> tal:on-error=3D"string:">
> </td>
> </tr>
> </table>
The problem with this, though, is that I don't want to call the database
in my template. I want the template to be re-used by 3 different DTML
methods: add, edit & search. When adding and searching, I'm not
executing a database query until the user hits the submit button. But in
the case of 'edit', I'm passing the personid that I want to edit, so the
edit dtml method executes the query and then invokes the template.
Here's what my edit method looks like (it's invoked with the parameters
"?personid=3Dx"):
<dtml-var standard_html_header>
<h2><dtml-var title_or_id> <dtml-var document_title></h2>
<dtml-in expr=3D"get_customer(pid=3Dpersonid)">
<form action=3D"&dtml-URL0;" method=3D"post">
<input type=3D"hidden" name=3D"personid" value=3D<dtml-var personid> >
<dtml-var genericform_html>
</form>
</dtml-in>
<dtml-var standard_html_footer>
I know that the form submission is wrong - that I'll need an
intermediate script to rewrite the data back into the tables. But right
now I'm just trying to populate the form with the values from the query.
It seems to me that this is an appropriate thing for templates. Is there
a better way to do this (re-usable forms)?
--=20
Colin Fox cfox@crystalcherry.com
CF Consulting Inc. GPG Fingerprint:
D8F0 84E7 E7CC 5C6C 9982 F1A7 A3EB 6EA3 BC97 572F
--=-seoVwI2Gu2ZxVt3qDund
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iD8DBQA8oN1mo+tuo7yXVy8RAkTOAKClVwxVio6vb0MCvFxXG7+gKOuqrACglt+z
BcnTRJiMBQjoigChFEOYC3c=
=PWdA
-----END PGP SIGNATURE-----
--=-seoVwI2Gu2ZxVt3qDund--