Forum OpenACS Q&A: Using ad_form's -actions switch

Collapse
Posted by Roberto Mello on
Hi All,

Can anyone enlighten me as how to use ad_form's -actions switch? I gathered that it takes a list of actions, and it displays my actions fine (Edit and Delete in my case).

But how do I act on the action? I thought I just had to do something like:

set action [form get_action ad]

if { [string equal $action "delete"] } {
        #
        # If the delete button was pressed
        #
        rp_internal_redirect ad-delete
        ad_script_abort
}

But when I hit the delete button it just shows me the form for editing, as if I had pressed the edit button. In which of ad_form's block should I check for the action? Or should the check be outside ad_form's declaration?

Thanks,

-Roberto

Collapse
Posted by Don Baccus on
Lars implemented this and he's on vacation ... I suggest you grep something like bug tracker to see how he's using it.
Collapse
Posted by Roberto Mello on
Thanks for the reply Don.

I did grep bug-tracker's sources before posting, but I didn't see the answer.

-Roberto

Collapse
Posted by Mark Aufflick on

Hi Roberto,

you get the action the user clicked with:

set action_id [form get_action contract]

do this OUTSIDE ad_form (at least that's what I do - up the top where you gather all your useful info like user_id, workflow_id etc.).

in any case, you need the action id before you check permissions. if you are using workflow, it would look like this:

if { ![workflow::case::action::available_p -case_id $case_id -action_id $action_id] } {
    handle the security violation
}

then i do this:

set actions [list]
if { [empty_string_p $action_id] } {
    if the action_id is an empty string, then we want to
    display the form, so build the list of actions. 

}

then I do the ad_form

in the on_submit block I act on the action as appropriate. if you are using workflow, it will look something like this:

if { ![empty_string_p $action_id] } { 
        foreach field [workflow::action::get_element -action_id $action_id -element edit_fields] {
            set row($field) [element get_value contract $field]
    }
}

followed by a db update or whatever your action requires

and at the end of the on_submit block I do a ad_returnredirect/ad_script_abort

Collapse
Posted by Roberto Mello on
Thanks for the reply Mark.

I knew about the [form get_action form_name] command. I looked extensively at the example in bug-tracker before posting, but I'm not using workflow.

I had tried the on_submit block but it didn't work. What did work was to put the check and appropriate action in the -edit_request block.

-Roberto