Forum OpenACS Q&A: How do I add different custom buttons in edit and new mode with ad_form?

After creating the log entry I currently have a redirect back to the same form where the log entry can be edited. In order to facilitate navigation back to the index page I then wanted to add a Done button on the edit form. I can't quite figure out how to do this - any tips?

You might want to look into the poorly documented (because I haven't finished the new doc I was writing) templating wizard for forms with multiple steps.

That said, you can conditionally add sections something like this:

if {![ad_form_new_p -key object_id]} {
    ad_form -extend -name my_form -form {
        {done:text(button) {label "Done}}
    }
}
Then in your processing section (on_submit or edit_data)
if {[exists_and_not_null done]} {
    ad_returnredirect back_to_previous_page
    ad_script_abort
}
You could also try and dynamically add  "-cancel_url {$return_url} -cancel_label {Done}" if the form is being edited. Or, rather, you may take advantage of the fact that if "cancel_url" is the empty string the button will vanish ...

But Dave's suggestion may be better.

BTW, we (all developers) seem to normally use the cancel_url to abort form input and redirect to some (arbitrary/non-generalized/unpredictible) url. The impression I get, though, is that most sites seem to use a "Cancel" button to clear the form, i.e., redirect to the same page. Am I wrong here?

What should "Cancel" mean, generally speaking?

(You're of course entitled to use it in any way you want, Peter, I just think it's an interesting question 😉

/Ola

Dave,

Looking forward to some documentation on the wizard. Great!

Can you tell me if the wizard is useful in conjunction with ad_form and, more precisely, with a "object-aev" (add-edit-view - "display" mode you know) kinda page, where (up to) three modes are covered by one single page?

Or does it imply several pages?

Maybe a dumb question, I should look for examples in the code :-b

Ola,

The wizard works fine with ad_form. You can actually progam a form to use the wizard or not.

Generally you will use the wizard with a multiple-page page flow. The last time I used it, it was around 12 steps. To use it I had to do everything using on_submit, so it is not always the best solution.

Peter,

Dave's suggestion is *definitely* better. I somehow managed to  overlook the fact that you were looking for a way to _submit_ a form, not to leave it all alone.

*grrr*

Ola, you mean the dreaded 'reset' html input type, which does not reload the same page but makes the browser clear all the form fields. This widget should be banned and sites that use it not taken seriously. I think the fact that our 'Cancel' buttons do something useful by actually going back to the object display page is perfectly fine.
Hi Dave,

I think you can use other sections in ad_form with wizards.  Look at what I have done in bcms-ui-wizard package.

Tilmann: Right. I was confusing "cancel" with "reset" (or vice versa).

I, too, think "reset" buttons suck (I think I formed that opinion after reading Philip's book ...). But I also like to conform to general standards, hence my question.

The only issue I have with a "Cancel" button is the element of surprise on the part of the user; "Oh! So this is where I wound up".