Save as Word Document | Find | English | Portugues(Brasil)

Creating User Modules
XmlFormCollection and ContextValue

Learn how to work with XMLFormCollection and the Context methods.

Table of contents
1. Initial Considerations
2. XmlFormCollection and ContextValue
3. XmlEditList
4. ProcessPageStateBase

On this page
Entering information through forms

Processing requests


Entering information through forms

So that interaction is possible with a user, XMLNuke provides an XMLObject to create a data entry form for interaction with the user. This object is called the EditForm

EditForm is a collection of XMLInputObjects and XMLInputButtons. Following is a list of the codes required to produce a result similar to that listed below:

Image

CSharp
// Create a Form
XmlFormCollection form = new XmlFormCollection(this._context, "module:sample", "Edit Form");
form.setJSValidate(true);
form.addXmlnukeObject(new XmlInputHidden("op", "2"));
form.addXmlnukeObject(new XmlInputLabelField("Caption", "Value"));
XmlInputTextBox text = new XmlInputTextBox("Required Field", "field1", "");
text.setRequired(true);
form.addXmlnukeObject(text);
XmlInputTextBox text2 = new XmlInputTextBox("Email type field", "field2", "");
text2.setRequired(true);
text2.setDataType(INPUTTYPE.EMAIL);
form.addXmlnukeObject(text2);
form.addXmlnukeObject(new XmlInputMemo("Memo", "field3", "Value"));
form.addXmlnukeObject(new XmlInputCheck("Checkbox", "check1", "Value"));
XmlInputCheck ic = new XmlInputCheck("Caption ReadOnly:", "check2", "Valor");
ic.setChecked(true);
ic.setReadOnly(true);
form.addXmlnukeObject(ic);
XmlInputTextBox itb = new XmlInputTextBox("Input ReadOnly:", "field4", "Valor");
itb.setReadOnly(true);
form.addXmlnukeObject(itb);
XmlInputButtons buttons = new XmlInputButtons();
buttons.addSubmit("Submit", "bs");
buttons.addReset("Reset", "br");
buttons.addButton("Button", "bt", "javascript:alert('ok')");
form.addXmlnukeObject(buttons);

block.addXmlnukeObject(form);

PHP
// Cria um Formulário
$form = new XmlFormCollection($this->_context, "module:sample", "Edit Form");
$form->setJSValidate(true);
$form->addXmlnukeObject(new XmlInputHidden("op", "2"));
$form->addXmlnukeObject(new XmlInputLabelField("Caption", "Value"));
$text = new XmlInputTextBox("Required Field", "field1", "");
$text->setRequired(true);
$form->addXmlnukeObject($text);
$text2 = new XmlInputTextBox("Email type field", "field2", "");
$text2->setRequired(true);
$text2->setDataType(INPUTTYPE::EMAIL);
$form->addXmlnukeObject($text2);
$form->addXmlnukeObject(new XmlInputMemo("Memo", "field3", "Value"));
$form->addXmlnukeObject(new XmlInputCheck("Checkbox", "check1", "Value"));
$ic = new XmlInputCheck("Caption ReadOnly:", "check2", "Valor");
$ic->setChecked(true);
$ic->setReadOnly(true);
$form->addXmlnukeObject($ic);
$itb = new XmlInputTextBox("Input ReadOnly:", "field4", "Valor");
$itb->setReadOnly(true);
$form->addXmlnukeObject($itb);
$buttons = new XmlInputButtons();
$buttons->addSubmit("Submit", "bs");
$buttons->addReset("Reset", "br");
$buttons->addButton("Button", "bt", "javascript:alert('ok')");
$form->addXmlnukeObject($buttons);

$block->addXmlnukeObject($form);	

Important information about processing the request:

  • Whenever it is necessary to request a page, it is advisable NOT to use a real address, but to use one from XMLNuke. For example:
    • To request a module: module:sample
    • To request a module and define an argument: module:sample?op=2
    • To request a static page: engine:xmlnuke?xml=home
    • To request an administration Control Panel: admin:engine
    • To request an administration module: admin:managexml
  • Every input object for editing can be "Read Only"; in other words, by changing a single parameter, the object will visibly be in read only mode. Even then, if the user submits a request the value will be sent.
  • When XMLNuke generates the HTML code it is capable of making JavaScript validations to determine if the field is mandatory or if the type of information entered corresponds to the type of information request. For example: EMAIL, DATE, NUMBER, TEXT, etc. (See INPUTTYPE)

Processing requests

To obtain a value that was posted by the form, the ContextValue method of the Context class must be used. The value returned will ALWAYS be of the String type. As a tip to facilitate module development, we suggest that the options are treated as functions instead of all of the functionalities being in one method of CreatePage. This is a good programming practice for XMLNuke and we strongly recommend its use.

CSharp
int option;
try
{
   option = Convert.ToInt32(this._context.ContextValue("op"));
}
catch
{
   option = 0;
}

switch (option)
{
   case 1:
   {
      this.Option1(xmlnukeDoc);
      break;
   }
   case 2:
   {
      this.Option2(xmlnukeDoc);
      break;
   }
   default:
   {
      this.DefaultOption(xmlnukeDoc);
      break;
   }
}

PHP
$option = $this->_context->ContextValue("op");
switch ($option)
{
   case 1:
   {
	$this->Option1($xmlnukeDoc);
	break;
   }
   case 2:
   {
	$this->Option2($xmlnukeDoc);
	break;
   }
   default:
   {
	$this->DefaultOption($xmlnukeDoc);
	break;
   }
}

Previous
Initial Considerations
Next
XmlEditList