Bambookit Home    Middleware

Chapter 19. Middleware




Creating a simple Form

<Widget setSize="100,300" setLayout="iconviewy,80,25,0">
<Edit setName="f1"/>
<Edit setName="f2"/>
<Edit seName="f3"/>
<Button setLabel="submit" addActionTarget="status,action,loadGui='submitform.php%2ctrue'"/>
<Widget setData="f1%2cf2%2cf3" seName="status" setLabel="ready"/>
</Widget>

The setData defines all the fields/widgets to submit to a URI address (using loadURL or loadGui attribute).
Note that instead of using a comma we use a URL encoded '%2c' ASCII equivalent, otherwise when the method gets looked up it will incorrectly search for a method with 'x' number of parameters instead of a single parameter

Before filling in the setData with the widget names, you would need to first set them using setName. In the Edit control we name the widgets f1, f2 and f3.

To be able to reference all the widgets that get submitted they first need to be named! To name them we use the setName attribute, this will be used to reference the Widget.

In the button addActionTarget we call the 'status' Widget's loadGui attribute. Since the widget 'status' is responsible for loading the gui it would also look locally to see if any data had been set. So the setData has to be on the 'invoked' widget.

The loadGui's update is set to true, in other words the loaded XML file will ONLY update already existing widgets that have a matching setName attribute.

The middleware script, submitform.php

<?php
// do some processing on the retrieved values
?>
<Widget setName="status" setLabel="processed"/>

The submitform.php script is purely a processing script. It retrieves the data, does some processing and returns a string indicating the state of the widget

Since this is an update script (loadGui flag set the update to true), we do not need to add any extra style information, since the widget will retain all of its previous attributes and we will only UPDATE the given attributes

If we wanted to include a dynamic message update by the script we can add this by changing the setLabel attribute
.. setLabel="<?php echo $process_result; ?>" ..

Adding checkboxes

<Widget setSize="100,300" setLayout="iconviewy,80,25,0">
<Edit setName="f1" setLabel="one"/>
<Edit setName="f2" setLabel="one"/>
<Edit setName="f3" setLabel="one"/>
<Checkbox setName="f4" setLabel="f4"/>
<Button setLabel="submit" addActionTarget="status,action,loadGui='submitform.php%2ctrue'"/>
<Widget setData="f1%2cf2%2cf3%2cf4" setName="status" setLabel="ready"/>
</Widget>

We update the setData with the new field 'f4', this is the name assigned to the checkbox. When the file is submitted the checkbox will be assigned either a 1 or 0.
A '1' if there is a checkmark.
A '0' if there is NO checkmark.

The default URI request (if the submit button is pressed right away) will look like this ...
..submitform.php?f1=one&f2=one&f3=one&f4=0

Adding Radio buttons

<Widget setSize="100,300" setLayout="iconviewy,80,25,0">
<Edit setName="f1" setLabel="one"/>
<Edit setName="f2" setLabel="one"/>
<Edit setName="f3" setLabel="one"/>
<Checkbox setName="f4" setLabel="f4"/>
<Radio setName="f5" setGroup="radio1" setLabel="f5"/>
<Radio setName="f6" setGroup="radio1" setLabel="f6"/>
<Button setLabel="submit" addActionTarget="status,action,loadGui='submitform.php%2ctrue'"/>
<Widget setData="f1%2cf2%2cf3%2cf4%2cf5%2cf6" setName="status" setLabel="ready"/>
</Widget>

Let's add two other widgets, radio button 'f5' and radio button 'f6'. They are grouped (setGroup) to radio1, this insures that only one or the other widget is at most selected. They pass the same value as a checkbox, either a '1' if selected or a '0'.

Let's say we select the radio button f5, then the URI we will get will look like this ...
..submitform.php?f1=one&f2=one&f3=one&f4=0&f5=1&f6=0

Submit groups

<Widget setSize="100,300" setLayout="iconviewy,80,25,0">
<Edit setName="f1" setLabel="one" setGroup="groupedit"/>
<Edit setName="f2" setLabel="one" setGroup="groupedit"/>
<Edit setName="f3" setLabel="one" setGroup="groupedit"/>
<Checkbox setName="f4" setLabel="f4"/>
<Radio setName="f5" setGroup="radio1" setLabel="f5"/>
<Radio setName="f6" setGroup="radio1" setLabel="f6"/>
<Button setLabel="submit" addActionTarget="status,action,loadGui='submitform.php%2ctrue'"/>
<Widget setData="groupedit%2cf4%2cradio1" setName="status" setLabel="ready"/>
</Widget>

This is useful in avoiding potential typos, we can group widgets together and submit the group instead of individually specifying each widget's name.

The URI will look like this ...
..submitform.php?f1=one&f2=one&f3=one&f4=0&f5=0&f6=0
As you can see the same as calling the widgets individually

Submit selected Buttons ONLY

<Widget setSize="100,300" setLayout="iconviewy,80,25,0">
<Edit setName="f1" setLabel="one"/>
<Edit setName="f2" setLabel="one"/>
<Edit setName="f3" setLabel="one"/>
<Checkbox setName="f4" setLabel="f4"/>
<Radio setName="f5" setGroup="radio1" setLabel="f5"/>
<Radio setName="f6" setGroup="radio1" setLabel="f6"/>
<Button setLabel="submit" addActionTarget="status,action,loadGui='submitform.php%2ctrue'"/>
<Widget setData="f1%2cf2%2cf3%2cf4%2cf5%2cf6" setDataGetSelected="true" setName="status" setLabel="ready"/>
</Widget>

The setDataGetSelected instructs the widget that all button types (button, checkbox and radio) are only passed in the URI request string IF they are selected (value set to 1), otherwise they are ignored

Let's say we select the checkbox button f4 (a value of 1), the the URI we will get will look like this ...
..submitform.php?f1=one&f2=one&f3=one&f4=1
The radio buttons since they were not selected were not included in the request

Adding Combobox

<Widget setSize="100,300" setLayout="iconviewy,80,25,0">
<Edit setName="f1" setLabel="one"/>
<Edit setName="f2" setLabel="one"/>
<Edit setName="f3" setLabel="one"/>
<Checkbox setName="f4" setLabel="f4"/>
<Radio setName="f5" setGroup="radio1" setLabel="f5"/>
<Radio setName="f6" setGroup="radio1" setLabel="f6"/>
<Combobox setName="f7" setLabel="none">
<Listbox setWidth="80">
<Item setLabel="Item1"/>
<Item setLabel="Item2"/>
<Item setLabel="Item3"/>
</Listbox>
</Combobox>
<Button setLabel="submit" addActionTarget="status,action,loadGui='submitform.php%2ctrue'"/>
<Widget setData="f1%2cf2%2cf3%2cf4%2cf5%2cf6%2cf7" setName="status" setLabel="ready"/>
</Widget>



Let's add a combobox, named 'f7'. Let's say we click the combobox and select Item2, the URI we will get will look like this ...
..submitform.php?f1=one&f2=one&f3=one&f4=0&f5=0&f6=0&f7=Item2

Notes

If we disable Widgets, the disabled widgets will not be included in the URI request.

The setPost attribute ONLY works on the loadGui command and not the loadUrl command. For loadUrl we can only send it through the GET protocol.