[ZPT] HTML data entry forms and ZPTs

Pim van Stam pim at vanstam.info
Wed May 11 04:53:28 EDT 2005


On Mon, 2005-05-09 at 13:59 -0400, Ken Winter wrote:
> 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).  
> 
> My little test page is at
> http://dhat.vega.zettai.net/clients/ridhwan/dhr3/deltest.htm.  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.
> 
> 
> The core ZPT code for this page is:
> 
> <h1> People (deletion test)</h1>
> <table tal:repeat="row here/dbobs/read_all_people" width="100%" border="0"
> cellspacing="0" cellpadding="0"><font face="Verdana, Arial, Helvetica,
> sans-serif">
> <tr> 
> <td width="44%" tal:content="string:${row/person_id} - ${row/first_name}
> ${row/middle_names} ${row/last_name}">Filler</td>
> <td width="56%">&nbsp;</td>
> </tr>
> </table>
> <p></p>
> <form action="python:here.dbobs.delete_person_py(context.REQUEST.person_id)"
> method="post" name="delete_form">


should/could be:

<form action="python:here.dbobs.delete_person_py" method="post"
name="delete_form">

> <p>Id of Person To Delete: 
>    <input type="text" name="person_id:int" />
> </p>
> <p> 
>    <input name="do_delete" type="submit" id="do_delete" value="Delete this
> Person" />
> </p>
> </form>
> <p>The &quot;Ids&quot; are the numbers in front of each person's name.</p>
> <p><a href="deltest.htm">Refresh This Page</a></p>
> <p tal:replace="python:here.dbobs.test1('MyParamValue')">Junk</p>	
> 
> 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:
> 
>        container.delete_person(person_id=id)
> 

should/could be:

  id = context.REQUEST.get('person_id')
  container.delete_person(person_id=id)

No parameters in the Parameter List of the script.


> and here's the ZSQL method "delete_person" that it calls:
> 
>        delete from person where person_id = <dtml-sqlvar person_id type=int>
> 

In the ZSQL Method "Arguments" you must have "person_id" added.

If this is working I suggest you to look at Controller Page Template and
Controller Python Script. You can then do easy error checking and do
something *after* deletion (succesful or not).

With regards

Pim van Stam
Netherlands






More information about the ZPT mailing list