cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Dumon <br...@outerthought.org>
Subject Re: CForms flowscript API musings
Date Mon, 26 Apr 2004 10:03:07 GMT
On Sun, 2004-04-25 at 18:36, Upayavira wrote:
> Christopher Oliver wrote:
> 
> > Bruno Dumon wrote:
> >
> >> I'm a bit annoyed by the current status of our flowscript API's for
> >> CForms. I'll leave the intro for what it is and just jump right into it:
> >>
> >> Form.showForm()
> >> ===============
> >> I find that this function hides too much of how a form is processed, and
> >> stands in the way of doing more advanced stuff.
> >>
> >> I propose that instead of Form.showForm(), we just let the user control
> >> it:
> >>
> >> var form = new Form("my_form_definition.xml");
> >> var finished = false;
> >> while (!finished) {
> >>    cocoon.sendPageAndWait("my-pipeline", {"form": form});
> >>    finished = form.processSubmit();
> >> }
> >>
> >> In this scenario, you need to write 5 lines instead of one
> >> form.showForm() call. However, it provides several advantages:
> >>
> >> * You can pass multiple form objects to the sendPageAndWait call (the
> >> FTT supports referencing different forms using the location attribute on
> >> ft:form-template)
> >>
> >>  
> >>
> > Can you describe this in more detail or provide some pseudo code on 
> > how a page with multiple forms would be sent and processed (or point 
> > to the documentation if there is already something about this)?
> 
> I've had need for this before: having a login form on every page as well 
> as another form. This is my attempt:
> 
> With Bruno's code above, you could put a <input type="hidden" 
> name="formID" value="login"/> hidden field into each form that 
> identifies which form was submitted. Then you'd do:
> 
> var loginForm = new Form("my_login_form_definition.xml");
> var mainForm = new Form("my_main_form_definition.xml");
> var finished = false;
> while (!finished) {
>   cocoon.sendPageAndWait("my-pipeline", {"login-form": loginForm, 
> "main-form", mainForm});
>   if (cocoon.request.formID == "login") {
>     finished = loginForm.processSubmit();
>   } else {  
>     finished = mainForm.processSubmit();
>   }
> }
>  
> That ought to do it.

Yep, that's what I had in mind.

>  There's a little hack with the 
> cocoon.request.formID, but it should work, as far as I can see.

I don't think that's a hack.

The point is however that there's always only one form which is
submitted and processed. So if the user edited data in different forms,
only the changes in the submitted form will be retained. The alternative
to avoid this is to create one form with multiple submit buttons.
Depends on what you want.

-- 
Bruno Dumon                             http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
bruno@outerthought.org                          bruno@apache.org


Mime
View raw message