[[#wd Lookup TitleRecipe7 ]]

Overview

To give the user the chance to review and confirm what he has entered into a form, show him the data on a confirmation page. Provide two buttons on this page either to accept or to cancel the final submission.

Preconditions

Steps to do:

  1. Define an Action that handles the form input and launches the confirmation page.
    Create a new subclass of the Action baseclass (check also Recipe 6).
    The only method you have to override is DoAction:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"bool MyCheckFormAction::DoAction(String &action, Context &c)"
    		"{"
    		"	Anything query = c.GetQuery();"
    		"	Anything fields = query["fields"];"
    		" "
    		"	// code to handle the input"
    		"	// store the content of the fields in the role store for later use"
    		"	Anything rs = c.GetRoleStore();"
    		"	for(int i= 0; i < fields.GetSize(); i++) {"
    		"		// all the fields should be stored directly, because Context.Lookup cannot find"
    		"		// MyFormData.MyFirstField  --  May an idea to provide this behaviour"
    		"		rs[fields.SlotName(i)]= fields[i];"
    		"	}"
    		"	// launch confirmation page"
    		"	action = "MyCheckFormAction";"
    		"	return true;"
    		"}"
    	}
    }]]
    
  2. Define the Layout of the confirmation page. Please check recipe 1 or 4 about the basics on how to create new pages. To present the data entered on the previous page, you should retrieve them from the role store using ContextLookupRenderers.

    Include as well a new FormRenderer that renders the two buttons. Check recipe 6 to learn more about using FormRenderer. Because the FormRenderer uses HTML-Templates you can render the field values directly there.

    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/ConfirmationForm {"
    		"	/Form {"
    		"		/Method "GET""
    		"		/Action "MyConfirmationAction""
    		"		/Template {"
    		"			"You have entered:"
    		"			"<p>My first field :[[ #wd Lookup { /ContextLookupName MyFirstField } ]]"
    		"			"<p>My second field :[[ #wd Lookup { /ContextLookupName MySecondField } ]]"
    		"			...."
    		"			"<p>[[#wd Lookup OkButtonRenderer ]] [[#wd Lookup CancelButtonRenderer ]]"
    		"		}"
    		"	}"
    		"}"
    	}
    }]]			
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/OkButtonRenderer {"
    		"	/Button {"
    		"		/Name "OkButton""
    		"		/Label {"
    		"			/String {"
    		"				/Default "I confirm""
    		"			}"
    		"		}"
    		"	}"
    		"}"
    	}
    }]]
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/CancelButtonRenderer {"
    		"	/Button {"
    		"		/Name "CancelButton""
    		"		/Label {"
    		"			/String {"
    		"				/Default "Cancel""
    		"			}"
    		"		}"
    		"	}"		
    		"}"
    	}
    }
    ]]
    
  3. Define an Action that handles the user input from the confirmation page. Like in step 1. subclass from Action and overwrite the DoAction method.
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"bool MyConfirmationAction::DoAction(String &action, Context &c)"
    		"{"
    		"	Anything query  = c.GetQuery();"
    		"	Anything fields = query["fields"];"
    		" "
    		"	// check if Ok button was pressed"
    		"	if (fields.IsDefined("OkButton") {"
    		"		// Retrieve the fields from the Rolestore"
    		"		ROAnything rs = c.GetRoleStore();"
    		" "
    		"		// ... and perform what you like to do in the Ok case"
    		"		String firstFirst  = rs["MyFirstField"].AsString("");  // just for fun"
    		"		String secondFirst = rs["MySecondField"].AsString(""); // just for fun"
    		" "
    		"		action = "InputOk";"
    		"		return true;"
    		"	}"
    		"	// the else case could return another "action"."
    		"}"
    	}
    }
    ]]
    
  4. Update Config.any and Role.any to properly incorporate the new page and actions. Make sure the pages are setup correctly in the Config.any's /Pages tag and the /Map tags of the role.any file(s) (Check Recipe 1).
    Define also the new Actions you have written:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/Actions {"
    		"	/MyFormAction {"
    		"		"MyForm""
    		"	}"
    		"	/MyConfirmationAction {"
    		"		"ConfirmationForm""
    		"	}"
    		" "
    		"	... other Actions"
    		"}"
    	}
    }]]
    

Remarks

Glossary

Related Topics