[Zope] Re: detail record editing

Hung Jung Lu hungjunglu@hotmail.com
Mon, 05 Jun 2000 11:14:04 PDT


--- In zope@egroups.com, Robert Del Huerto <rdh@s...> wrote:
>I can get Zope to generate a table and form like this from an SQL
>database.  I'm stuck after that.  The form only has one 'action' so how
>would I get it to handle the right function depending on the button that
>was pushed?

The short answer is: use JavaScript.

Instead of using <input type=submit ...>, I use <input type=button ...>. I 
guess an example is better than long explanations.

------------------------------------------------------------------
<center>
  <form name=my_form method=get>
  <input type=hidden name=handling_method>
  <input type=button value="Notes" onclick="go_notes()">
  <input type=button value="Edit" onclick="go_edit()">
  </form>
</center>

<script language="JavaScript1.1">
<!--//
if (document.images) {

function go_notes() {
    // example of a submission without handling method
    document.my_form.action = "&dtml.url-Notes;" ;
    document.my_form.submit();
}

function go_edit() {
    // example of a submission with handling method
    document.my_form.handling_method.name = "method_edit:method";
    document.my_form.action = "&dtml.url-Person;" ;
    document.my_form.submit();
}

}
// -->
</script>
------------------------------------------------------------------

In the first case (go_notes), your submission is sent to the "Notes" folder 
inside Zope, and it's handled by the conventional index_html method.

In the second case (go_edit), your submission is sent to the "Person" folder 
and it's handled by the "method_edit" method inside the "Person" folder. The 
"method_edit:method" tag in the above code tells Zope that "method_edit" is 
a method. It's a Zope thing, and you won't find it in JavaScript books. I 
find it useful to put my methods that handle a Person inside the Person 
folder, so I can have something like

  method_edit
  method_delete
  method_update
  ...

neatly lined up inside the Person folder. Another trick is, inside these 
handling methods, at the end I do a redirection, something like:

  <dtml-call "RESPONSE.redirect(MyNextPage.absolute_url() + '?person_id=%s' 
% my_person_id)">

That is, the handling methods only handle the logical part. For actually 
displaying the result, I use redirection to a displaying page.

Oh, on the &dtml.url-...; notation: if you need more complicated URLs, you 
cannot use the "&dtml.url-Object;" notation. You have to use "<dtml-var 
"MyFolder.MySubFolder.Object.absolute_url()">" notation instead.

Now you know how to make Zope work for you. :)

regards,

Hung Jung



________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com