Forum OpenACS Development: wizard tutorial

Collapse
Posted by Jeff Lu on
It appears that jun yamog has unlocked some secrets about the wizard. This is what I learned from our conversation.
 

#test-wizard.tcl
template::wizard create -action "test-wizard" -params {
    var_param1 var_param2 var_param3 #----> these are the variable/parameters that
    				     #the wizard will keep track of
} -steps {
    1 -label "Step 1" -url "step1"   #---->these are the different steps w/c the wizard will go though.
    2 -label "Step 2" -url "step2"   # ex: Lather, rinse, repeat......
    3 -label "Step 3" -url "step3"
}

template::wizard get_current_step    #this gets the current step of the wizard
				     #if you are in step 1 it returns 1....
#note: using template::wizard will return a multirow with name wizard
#########################################################
#test-wizard.adp



<include src="@wizard:current_url@">

<multiple name="wizard">
<p>
        <if @wizard.id@ eq @wizard:current_id@>
		<b><i>* @wizard:current_id@ - @wizard.label@</i></b>
      	</if>
        <else>
        	@wizard:current_id@ - @wizard.label@
       	</else>
</p>
</multiple>

########################################################
#next is the step1.tcl for the wizard

ad_form -name a_form -form {
	{form_elem1:text(text) {label "Element 1"}}
} -on_submit {
    template::wizard set_param var_param1 $form_elem1 #this simply sets the values of var_param1 to form_elem1
    template::wizard forward			      #this makes the wizard go to the next step. very important!
}

template::wizard submit a_form -buttons { next }      #this defines the buttons for the wizard
#buttons may be back next finish... forgot some (please try to look at the code and contribute :) )
ad_return_template form-template

##########################################################
#now step2.tcl

ad_form -name a_form -form {
	{form_elem2:text(text) {label "Element 2"}}
} -on_submit {
    template::wizard set_param var_param2 $form_elem2
    template::wizard forward
}

template::wizard submit a_form -buttons { back next }

ad_return_template form-template

###########################################################
#finally step3.tcl

ad_page_contract {} {
	var_param1:notnull
       	var_param2:notnull
}

ad_form -name a_form -form {
	{form_elem1:text(inform) {label "Element 1"} {value $var_param1}}
	{form_elem2:text(inform) {label "Element 2"} {value $var_param2}}
}

template::wizard submit a_form -buttons { back finish }

ad_return_template form-template


#since all of the variables are being kept track by the wizard then
#you can access it anytime using ad_page_contract

###########################################################
#here is also the code for form-template.adp
<formtemplate id="a_form"></formtemplate>

Collapse
2: Re: wizard tutorial (response to 1)
Posted by Don Baccus on
That's very useful, thanks for posting this.  Jun's a valuable resource!
Collapse
3: Re: wizard tutorial (response to 1)
Posted by Jun Yamog on
Hi Don,

Thanks.  Jeff will be also in due time.

Anyway since I am a bit still off openacs.  Can Jon G. or Joel A. put the post above somewhere where people can find it again?

Jon,

Can the simple wizard tutorial make it into your ad_form doc?  We do however need to move some of the comments.  As it breaks proc calls.  Grrr... much like ad_form was back then.  Thanks.

Collapse
4: Re: wizard tutorial (response to 1)
Posted by Jon Griffin on
I will add it today.