[[#wd Lookup TitleRecipe24 ]]

Overview

In the most webapplications we need some customer responses.
This example shows you a simple way to create a input form to gather information from customers by using the 'FormRenderer'.
The form tag is the most important element for creating HTML-Forms. All field elements ('FieldRenderer' with type=text, type=submit etc.) have to be defined inside a 'FormRenderer'.
A subclass of the Action class can then be used - by overwriting the DoAction method - to handle the user input. The user input can be accessed through the Contexts "Query" item, which itself contains a "fields" item storing all the fields and their values.

Preconditions

Steps to do:

  1. Define a FormRenderer, which holds all the needed fields and launches the action, that will handle the input. Include it in the Body part of the page, that is going to hold it.
    Sample:
    The Renderer specification for a FormRenderer may look as follows:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/UserInputForm {       # name of specified renderer"
    		"	/Form {             # kind of renderer (aliasname)"
    		"		/Method "GET"		 	 # method to send the message to the browser (POST or GET)"
    		"		/Action "MyDoSomething" # the Action, that should be triggered by COAST. It has to be an action name"
    		"		                        # that is defined in the Actions section of the config.any file."
    		"		/Template {"
    		"			"[[#wd Lookup AnElementOfForm ]]""
    		"			"[[#wd Lookup TextArea ]]""
    		"			"[[#wd Lookup PasswordField ]]""
    		"			"[[#wd Lookup CheckBox ]]""
    		"			"[[#wd Lookup SubmitButton ]]""
    		"		}"
    		"	}"
    		"}"
    	}
    }]]
    
  2. Inside a form there are a lot of possibilities to define elements.
    Some of them are shown in this example.
  3. Define an action item in the file Config.any and add a action/page map in Role.any.
    File Config.any:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/Actions {"
    		"	aliases for "Actions""
    		"	/MyDoSomething {       { this name is mapped to a new C++ Class derived from the abstract class Action }"
    		"		"DoSomething"       { aliasname }"
    		"	 }"
    		"}"
    	}
    }]]
    
    File Role.any:
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"/Ex4Page {"
    		"	/GoExample4  "Ex4Page" #returns obviously to the same page again"
    		"}"
    	}
    }]]
    
  4. Write a new C++ class for a customized action e.g.
    [[#wd DisplayAnythingRenderer {
    	/AnythingInfo {
    		"//---- DoSomething -------------------------------------------------------------------"
    		" "
    		"class DoSomething : public Action {"
    		"public:"
    		"	DoSomething();"
    		"	bool DoAction(String &action, Context &c);"
    		"};"
    		" "
    		"//---- DoSomething -------------------------------------------------------------------"
    		"RegisterAction(DoSomething);"
    		" "
    		"DoSomething::DoSomething()"
    		"{"
    		"}"
    		" "
    		"bool DoSomething::DoAction(String &action, Context &c)"
    		"{"
    		"	Anything query = c.GetQuery();"
    		"	"
    		"	StartTrace(DoSomething.DoAction);	// debugging"
    		"	TraceAny(query, "query");"
    		"	"
    		"	// make the wanted checks"
    		"	Anything result;"
    		"	if (query.LookupPath( result, "fields.loginname" )) {"
    		"		String thatsthename = result.AsString("");"
    		"		if ( thatsthename.Length() ) {"
    		"			Anything tmpStore = c.GetTmpStore();"
    		"			"
    		"			tmpStore["thatsthename"] = thatsthename; // name of defined textfield  "
    		"			if (thatsthename == "Markus") { // analyze the input data"
    		"				action = "GoExample4";  // result action (remains ot the same page)"
    		"				return true; "
    		"			}"
    		"		}"
    		"	}"
    		"	action = "GoExample4";  // default action (remains ot the same page)"
    		"	return true;"
    		"}"
    	}
    }]]
    

Remarks

Glossary

Related Topics