[Zope] form and zpt question

Haim Ashkenazi haim at babysnakes.org
Sun Jan 16 07:41:39 EST 2005


Hi

I'm looking for a way to pass the values entered in a form (zpt) back to
the same page after processing it in a python script. say I have this zpt:

----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html metal:use-macro="container/index_html/macros/page">
    <td metal:fill-slot="body-content">
    <h2>Add a new Client</h2>
    <p>
        In the form below, you can add New client. the "price" fields (if
        filled) will be used for calculations in the reports.<br>
        Please make sure that you check that the client do not exist in the
        list below!  two names of the same client can cause problems when
        producing  reports.<br>
    </p>
    <ul>
        <li>Already defined customers:&nbsp&nbsp
        <select name="customer">
            <option tal:repeat="clients container/show_clients"
                    tal:content="clients/name">Clients</option>
        </select>
        </li>
    </ul>
    <!-- if there was error processing the request -->
    <p tal:condition="options/error_message | nothing">
        <font color="Red">
            ERROR:&nbsp <em tal:content="options/error_message">error here</em>
        </font>
    </p>
    <form action="add_client.py" method="post" onSubmit="return validateStandard(this);">
    <table cellpadding="5">
        <tr align="left">
            <th>Customer name:</th>
            <td><input name="customer" ></td>
        </tr>
        <tr align="left">
            <td>Price - on site:</td>
            <td><input name="onsite" size="5"></td>
        </tr>
        <tr align="left">
            <td>Price - remote:</td>
            <td><input name="remote" size="5"></td>
        </tr>
        <tr align="left">
            <td>Price - phone support:</td>
            <td><input name="phone" size="5"></td>
        </tr>
        <tr align="left">
            <td><button name="submit" value="submit">Submit Customer</button></td>
        </tr>
    </table>
    </form>
    </td>
</html>
------------------------

and this script:
--------------------
##parameters=REQUEST
##title=
##
# parse input from "addclient" form and returns the result.

req = REQUEST

# if no name was specified
if not req.customer:
    return container.addclient(error_message = "You must specify the customer's name")

context.add_client(name = req.customer, onsite = req.onsite,
                     remote = req.remote, phone = req.phone)

response = container.clientsubmited(name = customer)
return response
----------------------

in case of an error, it re-renders the template with the error above. this 
works fine, but I want it to keep the values already entered in the form, 
not to give me a blank form. one way to specify them when calling the
template from the script, but in large forms this will result in a very
long parameter list. is there one object that holds all the values that I
can pass back to the template?

thanx
-- 
Haim




More information about the Zope mailing list