[Zope] Populating a form

Colin Fox cfox@crystalcherry.com
27 Apr 2002 00:33:28 -0700


--=-YyOz+j63oSShuTcvhom6
Content-Type: multipart/mixed; boundary="=-Zc2yJpWK0yY3ajF4EA+f"


--=-Zc2yJpWK0yY3ajF4EA+f
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

On Fri, 2002-04-26 at 08:27, McDonnell, Larry wrote:
>=20
> Hi,
>=20
> I am new to the Zope environment but I have been successful. I have been
> able to add odbc database connection and through a form input information=
 to
> this database. Now I would like to view this information. I have set up z
> sql methods and I can see the info under the manage_test format. I would
> like to be able to re-populate my output form (its a copy of the input fo=
rm
> but without the submit). I have gone through the zope book but maybe I
> missed something. Any examples or pointer I can use, thanks.

This sounds like the exact issue I was dealing with a few weeks ago. I
wanted to use one form for both input and review.

Attached to this email are some files that make up my solution. The
basic idea is to have a generic form that gets included either by the
input or the edit pages. I also have a python script included that
populates the REQUEST object with the results from the database.

What I'm doing here is quite possibly the clumsy way to solve the
problem, but it worked for me. (I've since moved on to a more ZPT
centric way of doing things).

The 'edit' page is the primary page, and calls all the others.

I hope this helps.

--=20
Colin Fox                                       cfox@crystalcherry.com
CF Consulting Inc.                                    GPG Fingerprint:
                    D8F0 84E7 E7CC 5C6C 9982  F1A7 A3EB 6EA3 BC97 572F

--=-Zc2yJpWK0yY3ajF4EA+f
Content-Disposition: attachment; filename=edit
Content-Type: text/plain; name=edit; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<dtml-var standard_html_header>
<h2><dtml-var title_or_id> <dtml-var document_title></h2>

<dtml-call expr=3D"get_customer_script(pid=3Dpersonid)">
<form action=3D"&dtml-URL0;/updatemethod_html" method=3D"post">
<input type=3D"hidden" name=3D"personid" value=3D<dtml-var personid> >

<table border=3D"1">
 <tr>
  <td>
   <dtml-var genericform_html>
  </td>
 </tr>
 <tr>
  <td colspan=3D"2" align=3D"center"><INPUT type=3D"submit" name=3D"update"
      value=3D"Update">
    </td>
 </tr>
</table>
</form>
<dtml-var list_phones_html>
<hr>
<dtml-var list_comments_html>
<dtml-var standard_html_footer>

--=-Zc2yJpWK0yY3ajF4EA+f
Content-Disposition: attachment; filename=genericform_html
Content-Type: text/plain; name=genericform_html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<table><tr>
<td valign=3D"top">
<!--
 This is the table on the left
-->
<table>
 <tr>
     <td><LABEL for=3D"salutation">Salutation: </LABEL></td>
     <td><INPUT type=3D"text" name=3D"salutation" value=3D""
	    id=3D"salutation"
          tal:attributes=3D"value request/salutation"
          tal:on-error=3D"string:">
     </td>
 </tr>
 <tr>
     <td><LABEL for=3D"firstname">First name: </LABEL></td>
     <td><INPUT type=3D"text" name=3D"first_name" value=3D""
	    id=3D"firstname"
          tal:attributes=3D"value request/first_name"
          tal:on-error=3D"string:">
     </td>
 </tr>
 <tr>
    <td><LABEL for=3D"middlenames">Middle names: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"middle_names" value=3D""
	    id=3D"middlenames"
          tal:attributes=3D"value request/middle_names"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"lastname">Last name: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"last_name" value=3D""
	    id=3D"lastname"
          tal:attributes=3D"value request/last_name"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"suffix">Suffix: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"suffix" value=3D""
	    id=3D"suffix"
          tal:attributes=3D"value request/suffix"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"prefname">Preferred name: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"pref_name" value=3D""
	    id=3D"prefname"
          tal:attributes=3D"value request/pref_name"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
  <td><LABEL for=3D"email">email: </LABEL></td>
  <td><INPUT type=3D"text" name=3D"email" value=3D""
	    id=3D"email"
          tal:attributes=3D"value request/email"
          tal:on-error=3D"string:">
  </td>
 </tr>
 <tr>
   <td>
      <INPUT type=3D"radio" name=3D"gender" value=3D"M"
         checked=3D"CHECKED"
	 tal:define=3D"gen request/gender"
	 tal:attributes=3D"checked python:here.checkedfunc(desired=3D'M',actual=3D=
gen)"
	 tal:on-error=3D"string:">
	 Male
   </td>

   <td><INPUT type=3D"radio" name=3D"gender" value=3D"F"
	 tal:define=3D"gen request/gender"
	 tal:attributes=3D"checked python:here.checkedfunc(desired=3D'F',actual=3D=
gen)"
	 tal:on-error=3D"string:">
	Female
    </td>
 </tr>
</table>
</td> <!-- End of the left column/table thingy -->

<!-- -------------------------------------------------------- -->
<td valign=3D"top"> <!-- Now the main address -->
<table>
 <tr>
     <td><LABEL for=3D"street_addr">Street: </LABEL></td>
     <td><INPUT type=3D"text" name=3D"street_addr" value=3D""
	    id=3D"street_addr"
          tal:attributes=3D"value request/street_addr"
          tal:on-error=3D"string:">
     </td>
 </tr>
 <tr>
     <td><LABEL for=3D"city">City: </LABEL></td>
     <td><INPUT type=3D"text" name=3D"city" value=3D""
	    id=3D"city"
          tal:attributes=3D"value request/city"
          tal:on-error=3D"string:">
     </td>
 </tr>
 <tr>
    <td><LABEL for=3D"stateprov">State/Prov: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"stateprov" value=3D""
	    id=3D"stateprov"
          tal:attributes=3D"value request/stateprov"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"country">Country: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"country" size=3D"2" value=3D""
	    id=3D"country"
          tal:attributes=3D"value request/country"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"postalcode">Postal Code: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"postalcode" value=3D""
	    id=3D"postalcode"
          tal:attributes=3D"value request/postalcode"
          tal:on-error=3D"string:">
    </td>
 </tr>
</table>
</td>

<td valign=3D"top" style=3D"background: #cccccc;"> <!-- Now the mailing add=
ress -->
<table>
 <tr> <td colspan=3D"2" align=3D"center"><strong>Mailing</strong></td></tr>
 <tr>
     <td><LABEL for=3D"mail_street_addr">Street: </LABEL></td>
     <td><INPUT type=3D"text" name=3D"mail_street_addr" value=3D""
	    id=3D"mail_street_addr"
          tal:attributes=3D"value request/mail_street_addr"
          tal:on-error=3D"string:">
     </td>
 </tr>
 <tr>
     <td><LABEL for=3D"mail_city">City: </LABEL></td>
     <td><INPUT type=3D"text" name=3D"mail_city" value=3D""
	    id=3D"mail_city"
          tal:attributes=3D"value request/mail_city"
          tal:on-error=3D"string:">
     </td>
 </tr>
 <tr>
    <td><LABEL for=3D"mail_stateprov">State/Prov: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"mail_stateprov" value=3D""
	    id=3D"mail_stateprov"
          tal:attributes=3D"value request/mail_stateprov"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"mail_country">Country: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"mail_country" size=3D"2" value=3D""
	    id=3D"mail_country"
          tal:attributes=3D"value request/mail_country"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"mail_postalcode">Postal Code: </LABEL></td>
    <td><INPUT type=3D"text" name=3D"mail_postalcode" value=3D""
	    id=3D"mail_postalcode"
          tal:attributes=3D"value request/mail_postalcode"
          tal:on-error=3D"string:">
    </td>
 </tr>
 <tr>
    <td><LABEL for=3D"use_mail_addr">Use Mailing Addr: </LABEL></td>
    <td><INPUT type=3D"checkbox" name=3D"use_mail_addr"
         value=3D"Y"
	 id=3D"use_mail_addr"
	 tal:define=3D"gen request/use_mail_addr"
	 tal:attributes=3D"checked python:here.checkedfunc(desired=3D'Y',actual=3D=
gen)"
         tal:on-error=3D"string:">
    </td>
 </tr>
</table>
</td>

</tr></table>


--=-Zc2yJpWK0yY3ajF4EA+f
Content-Disposition: attachment; filename=get_customer_script
Content-Type: text/plain; name=get_customer_script; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

## Script (Python) "get_customer_script"
##bind container=3Dcontainer
##bind context=3Dcontext
##bind namespace=3D
##bind script=3Dscript
##bind subpath=3Dtraverse_subpath
##parameters=3Dpid
##title=3D
##
res =3D context.get_customer(personid=3Dpid)
d =3D res.dictionaries()[0]
for k in d.keys():
    context.REQUEST.set(k, d[k])

--=-Zc2yJpWK0yY3ajF4EA+f
Content-Disposition: attachment; filename=updatemethod_html
Content-Type: text/html; name=updatemethod_html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<html>
<body>
<dtml-if name=3D"update">
    <dtml-try>
	<dtml-call name=3D"updatemethod_sql">
	<dtml-call expr=3D"RESPONSE.redirect(URL2+'/edit?personid=3D'+personid)">
    <dtml-except>
	<p>Couldn't update user: <dtml-var error_value> </p>
    </dtml-try>
<dtml-else>
    <dtml-call expr=3D"RESPONSE.redirect('index_html')">
</dtml-if>
</body>
</html>

--=-Zc2yJpWK0yY3ajF4EA+f--

--=-YyOz+j63oSShuTcvhom6
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

iD8DBQA8ylRHo+tuo7yXVy8RAvllAJ4hkxmgFgL/2DxJT9B6MUHYmoimgQCeMcsT
kK/ANgbnl7eNhtGE1WpVO3A=
=7sZS
-----END PGP SIGNATURE-----

--=-YyOz+j63oSShuTcvhom6--