[Zope] Calling DTML Methods from JavaScript?

Dirk Datzert Dirk.Datzert@rasselstein-hoesch.de
Tue, 25 Dec 2001 16:24:42 +0100


Have you looked at the Formulator product ?

It does most of the things you need.

Form render, input and validation

Dan Shafer schrieb:

> I'm sure I'm just overlooking something obvious here, but after
> spending several hours at this today I'm throwing up my hands.
>
> The goal here was (I thought) pretty simple:
>
> 1. User fills out a form.
> 2. If he checks a radio button and then doesn't provide text in a
> related field, I remind him of his inconsistency, leave him on the
> HTML form where he was, and select the field that needs completion.
> Outside Zope, this is a piece-o-cake. Done it hundreds of times.
> 3. If he behaves as expected, the MySQL database gets updated and the
> user gets a thank you page.
>
> In the JavaScript I use on the client side (I can't see a way to keep
> the user on the form using dtml), I have a conditional. The if
> portion pops up a dialog, reminding the user of his or her oversight,
> then selects the improperly omitted field. The else clause is
> _supposed_ to call the dtml method that updates the MySQL database
> and thanks the user for the submission. That's where the problem
> arises.
>
> In the <FORM> tag, I have the DTML method as the action. I also added
> a call to the JavaScript function using an onSubmit handler. The
> onSubmit handler gets called, the user gets reminded of the
> oversight, and the function returns false. This is _supposed_ (ECMA
> rules) to prevent the form from being submitted so the form action
> shouldn't take place. That's not what happens. Instead, the user gets
> reminded of the omission and then the thank you page shows up anyway.
> The MySQL database gets updated and it shouldn't.
>
> I tried in the else clause just having this line:
>
> else
> <dtml-call addAndAcknowledge>
>
> But when I do that, it _appears_ that Zope parses the script (which
> is in an overridden standard_html_header dtml method) because it
> gives me errors indicating a bad submission to the database on
> loading the page with the form.
>
> I tried enclosing the dtml-call in curly braces (optional JavaScript
> syntax; I was getting desperate) but that had zero effect.
>
> So the question I ended up with (and it may not be the right one;
> half of success is knowing what questions to ask and I'm not sure I
> have this one right) is, "How do you call a DTML method from a
> JavaScript?"

You can't Call JavaScript from DTML. JavaScript runing is on the client
side.
DTML is running on the  Zope server side

> I searched all the Tips and How-Tos, and did a search on
> Zope.org using "JavaScript" and then "DTML and JavaScript" and then
> "Zope and JavaScript" as terms. No joy but hours of pain (and a few
> good tidbits picked up in the process, so all was not lost.)
>
> What am I missing?
> --
> Dan Shafer, Author-Consultant
> http://www.danshafer.com
> http://www.shafermedia.com
>
> _______________________________________________
> 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 )