Custom widgets
To create custom widget derive appropriate built-in widget (or simple widget) class and override getEditableControl() method. If needed getControl() and getData() methods can be reimplemented.
getControl() returns array with template variables to be displayed for non-editable control.
getData() processes the form submissions and returns the data.
* Creating a textarea widget from text simple widget
<?php
class wsWebFormWidgetTextarea extends miWebFormFieldText {
public function getEditableControl()
{
$id = isset($this->_properties['id'])?' id="' . $this->_properties['id'] . '"':'';
// Get the submitted value
$value = $this->_webForm->getFormData($this->_fieldName);
// Escape the submitted value (protects from HTML code injections)
$value = miI18N::htmlEscape($value);
// Construct the widget HTML code
$widget = '<textarea name="' . $this->_fieldName . '"' . $id . '>' . $value . '</textarea>';
// Function returns array where keys are the fields names, and the values are their corresponding widget HTML code
return array($this->_fieldName => $widget);
}
}
?>