<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7226.0">
<TITLE>RES: [ZPT] HTML data entry forms and ZPTs</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">You don't need to pass explicitly person_id. When the ZSQL method's arguments and form fields have the same names, the arguments are automatically collected from the REQUEST object. Otherwise you have to call the ZSQL method with explicit arguments.</FONT></P>
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Another thing that you have to consider is that context.REQUEST.person_id (in your form action) contains the value of this variable<B> before</B> you submit the form, and not<B> after</B>.</FONT></P>
<P><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">Zenrique.</FONT>
</P>
<UL>
<P><FONT FACE="Courier New"><SPAN LANG="pt-br"></SPAN></FONT><SPAN LANG="pt-br"> <FONT SIZE=1 FACE="Tahoma">-----Mensagem original-----</FONT></SPAN>
<BR><SPAN LANG="pt-br"><B><FONT SIZE=1 FACE="Tahoma">De: </FONT></B> <FONT SIZE=1 FACE="Tahoma">zpt-bounces@zope.org [<A HREF="mailto:zpt-bounces@zope.org">mailto:zpt-bounces@zope.org</A>] </FONT><B> <FONT SIZE=1 FACE="Tahoma">Em nome de</FONT></B> <FONT SIZE=1 FACE="Tahoma">Ken Winter</FONT></SPAN>
<BR><SPAN LANG="pt-br"><B><FONT SIZE=1 FACE="Tahoma">Enviada em: </FONT></B> <FONT SIZE=1 FACE="Tahoma">segunda-feira, 9 de maio de 2005 15:00</FONT></SPAN>
<BR><SPAN LANG="pt-br"><B><FONT SIZE=1 FACE="Tahoma">Para: </FONT></B> <FONT SIZE=1 FACE="Tahoma">zpt@zope.org</FONT></SPAN>
<BR><SPAN LANG="pt-br"><B><FONT SIZE=1 FACE="Tahoma">Assunto: </FONT></B> <FONT SIZE=1 FACE="Tahoma">[ZPT] HTML data entry forms and ZPTs</FONT></SPAN>
</P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">I'm trying to build a data-entry form using only ZPTs (no DTML, except in the ZSQL methods that put the data into the DB). </FONT></SPAN></P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">My little test page is at <A HREF="http://dhat.vega.zettai.net/clients/ridhwan/dhr3/deltest.htm">http://dhat.vega.zettai.net/clients/ridhwan/dhr3/deltest.htm</A>. At the top are the persons currently in the site’s MySQL database; the retrieval of them works fine. What doesn't work is the attempt to delete a person by entering an Id into the field and pressing the “Delete this Person” button. </FONT></SPAN></P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">The core ZPT code for this page is:</FONT></SPAN>
</P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><h1> People (deletion test)</h1></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><table tal:repeat="row here/dbobs/read_all_people" width="100%" border="0" cellspacing="0" cellpadding="0"><font face="Verdana, Arial, Helvetica, sans-serif"></FONT></SPAN></P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><tr> </FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><td width="44%" tal:content="string:${row/person_id} - ${row/first_name} ${row/middle_names} ${row/last_name}">Filler</td></FONT></SPAN></P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><td width="56%">&nbsp;</td></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></tr></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></table></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><p></p></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><form action="python:here.dbobs.delete_person_py(context.REQUEST.person_id)" method="post" name="delete_form"></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><p>Id of Person To Delete: </FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> <input type="text" name="person_id:int" /></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></p></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><p> </FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> <input name="do_delete" type="submit" id="do_delete" value="Delete this Person" /></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></p></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"></form></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><p>The &quot;Ids&quot; are the numbers in front of each person's name.</p></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><p><a href="deltest.htm">Refresh This Page</a></p></FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"><p tal:replace="python:here.dbobs.test1('MyParamValue')">Junk</p> </FONT></SPAN>
</P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">Here is the entire body of the Python script "delete_person_py(id)" that the ZPT <form> tag is trying to call and that in turn invokes the ZSQL "delete_person" method:</FONT></SPAN></P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> container.delete_person(person_id=id)</FONT></SPAN>
</P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">and here's the ZSQL method "delete_person" that it calls:</FONT></SPAN>
</P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New"> delete from person where person_id = <dtml-sqlvar person_id type=int></FONT></SPAN>
</P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">I think I have the problem narrowed down to the call from the ZPT to the Python script, which somehow fails to pass the form variable "person_id" that is needed to select the person to delete. For example, I know that I can do deletes successfully by invoking the Python script directly from the ZMI. I have tried every variation on the data-passing that I can think of. I’ve tried calling the ZSQL method directly from the ZPT. The successful call to another script at the bottom of the page rules out a bunch of other problems. I have scoured every Zope reference I can find - there are plenty of examples of doing forms with DTML (e.g. <A HREF="http://www.faqts.com/knowledge_base/view.phtml/aid/5518/fid/567">http://www.faqts.com/knowledge_base/view.phtml/aid/5518/fid/567</A>), but none for doing forms with ZPTs.</FONT></SPAN></P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">There’s just gotta be a “well, duh” simple solution to this, but it has escaped me.</FONT></SPAN>
</P>
<P><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">- Thanks in advance for your help!</FONT></SPAN>
<BR><SPAN LANG="en-us"><FONT SIZE=2 FACE="Courier New">- Ken Winter << Arquivo: ATT1988512.txt >> << Arquivo: deltest.htm >> </FONT></SPAN>
</P>
</UL>
</BODY>
</HTML>