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.
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/Renderers {" " /FormRenderer { Form }" "}" } }]]
[[#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 ]]"" " }" " }" "}" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/AnElementOfForm { # name of specified ContextLookupRenderer" " /Text { # kind of renderer (aliasname)" " /Name username # the information will be able to catch by this name in the query of an action " " /Value UserNameField" " /Size 32" " }" "}" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/TextArea { # textfield with several input lines" " /TextAreaRenderer {" " /Name textarea" " /Value TextAreaField" " }" "}" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/PasswordField { # for the inputed data a '*' instead of the realy data is displayed" " /Text {" " /Name resultPassword" " /Value lookupPasswdDefault" " /Unreadable 1" " /Size 16" " }" "}" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/CheckBox { # checkbox to set true/false (example: switch on/off a feature) " " /CheckBox {" " /Name BoxField" " /Value "on"" " }" "}" } }]]
[[#wd DisplayAnythingRenderer { /AnythingInfo { "/SubmitButton { # submit button to submit entries" " /Button {" " /Name submit" " /Label {" " /String {" " /Default "Next Page"" " }" " }" " }" "}" } }]]
[[#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" "}" } }]]
[[#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;" "}" } }]]