[Zope] Populating a form

Jon Erickson jon.erickson@neicoltech.org
26 Apr 2002 15:06:59 -0500


To summarize what you need:

1. HTML form with a doc_id variable (text box).

2. ZSQL method with a query that accepts doc_id as a parameter.

SELECT * 
FROM documents
WHERE doc_id = <dtml-sqlvar doc_id type="string">

3. DTML Method to display the results of the query.  In the following
example "documents_by_doc_id" is your ZSQL method.

<dtml-in expr="documents_by_doc_id(REQUEST)">
  <dtml-var doc_num>, 
  <dtml-var date_created>, 
  <dtml-var author><br>
</dtml-in>

Set the html forms "action" variable to the name of the dtml method used
to display database records.  When the form is submitted to the dtml
method, it passes the REQUEST variable, which contains doc_id, to the
zsql method and uses the <dtml-in> statement to iterate over the query
results.  This is obviously a simplified example but it should point you
in the right direction.

Jon

On Fri, 2002-04-26 at 14:20, McDonnell, Larry wrote:
> Hi Ian,
> 
> Thanks for the reply. I know it is early there and a Friday/Saturday and
> this can wait until Monday.
> 
> I see that I need to call the record from an http address and this assumes
> the users have something between their ears. I need this query to appear on
> the screen for the users to enter. The project I am piloting is to move to
> web based forms for our factory employees to input data and if someone wants
> to review it pull up an existing record by entering for example
> "doc_number". The user will enter this and hit a submit button. The form
> outline is what they are familiar to and I need to work on this premise.
> 
> I created the input form using dreamweaver. I added the dtml statements and
> sql methods. I can populate the database. I know this is old time stuff
> using a different environment. I am trying to move to a thin client out on
> the factory floor and eliminate buying software for each workstation.
> 
> If I use my z sql query, the data is displayed in a table/record generate by
> "manage_test" form. I guess my question is do I need to script the query to
> return the record I am looking for and make a dtml call from the form? If
> that is the case, does anyone have a script talking to a database so I can
> see an example.
> 
> -----Original Message-----
> From: icottee@localhost.localdomain
> [mailto:icottee@localhost.localdomain]On Behalf Of Ian J Cottee
> Sent: Friday, April 26, 2002 1:14 PM
> To: McDonnell, Larry
> Cc: 'zope@zope.org'
> Subject: Re: [Zope] Populating a form
> 
> 
> Hi Larry
> 
> "McDonnell, Larry" <lmcdonnell@protonenergy.com> writes:
> 
> > 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
> form
> > but without the submit). I have gone through the zope book but maybe I
> > missed something. Any examples or pointer I can use, thanks.
> 
> If I understand you correctly, you want to have a form that displays
> just one record on the screen? A very basic method would be to create
> one ZSQL method to get your item and one DTML Document to display
> it. So your SQL Method would look something like this
> 
> <params>pk</params>
> SELECT CODE, DESCRIPTION, PRICE FROM MYFILE WHERE 
>         ID = <dtml-sqlvar pk type=int>
> 
> Lets say that simple method is called sqlSelect
> 
> Now create a form in the same folder and it will look something like
> this (untested)
> 
> <dtml-var standard_html_header>
> <dtml-in sqlSelect>
>    My Code Is: <dtml-var CODE null=""><br>
>    My Description Is: <dtml-var DESCRIPTION null=""><br>
>    My Price is: <dtml-var PRICE fmt="%3.2f" null="0.00">
> </dtml-in>
> <dtml-var standard_html_footer>
> 
> If that form was called view_data you can call it with something like 
> 
> http://my.web.server:8080/view_data?pk=1
> 
> Which would display the data for the record with an ID of 1. You won't
> get may design awards for the interface though ;-)
> 
> If you are putting the data back into the input fields you'd have just
> have stuff like 
> 
>    <input type="text" name="iDescription" value="<dtml-var DESCRIPTION
> null="">">
> 
> hth
> 
> Ian 
> 
> PS It's 2am here so forgive me for any mistakes above but that should
> drive you in the right direction. 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>