Source for file WebForm.php
Documentation is available at WebForm.php
* Contains the miWebForm class
* @copyright Copyright (c) 2006,2007 Mirchev Ideas Ltd. All rights reserved.
* @copyright Copyright (c) 2006,2007 Mirchev Ideas Ltd. All rights reserved.
* Array that describes the output and input of each web field
* Array with field objects
* Array with data to displayed by the widgets
* A reference to the error hanlder object
* Template section infos to be added when parsing the template
* Reference to the message object, or null
* Constructs the miWebForm
* @param array $formDataRow
* Returns the form data row
* @param string $formData
* Returns a form data value
* Adds new template section info
* @param array $formProperties the form properties array
// Build all field objects
foreach ($formProperties as $key =>
$formField) {
$properties = isset
($formField['properties']) ?
$formField['properties'] :
array();
$field =
new $formField['field']($this, $properties);
$field->setFieldName($formField['data']);
if (isset
($formField['validator'])) {
// Multiple validators per field
if (is_array($formField['validator'])) {
foreach ($formField['validator'] as $validator) {
$this->_validators[$key][] =
new $validator($this, $formField['data']);
$this->_validators[$key] =
new $formField['validator']($this, $formField['data']);
* Adds a validator for a field
* @param string $fieldName
* @param miValidator $validator
public function addValidator($fieldName, miValidator $validator)
if ($formField['data'] !=
$fieldName)
// Check for 3 possible cases:
// 1. there is no validator - set it as reference
// 2. there is one validator - convert to array of validators
// 3. there are already more than one validators - add the validator to the array of validators
* Removes all validators for a field
* @param string $fieldName
if ($formField['data'] !=
$fieldName)
* @param string $fieldName the name of the field whose widget to return
* @return miWidget|nullan object that is extends miWidget, or null if not found
if ($formProperty['data'] ==
$fieldName)
* Adds new form field object
* @param string $fieldName
* @param miBaseWidget $widget
public function addWidget($fieldName, miBaseWidget $widget)
* Parses the form template
* @param string $templateName
* @param boolean $isEditable if the form will contain the editable fields/widgets
* @return string the html for the form
public function parse($templateName, $isEditable)
$t->readTemplate($templateName);
$disp =
$formField->getEditableControl();
$disp =
$formField->getControl();
foreach ($disp as $key =>
$value) {
$fieldValues['%%' .
strtoupper($key) .
'%%'] =
$value;
$t->assignArray($fieldValues);
$errors->assignErrors($t);
$t->assignArray($this->getMessageObj()->getMessageTemplateVars());
return $t->templateParse();
* Returns the message object
* if $this->_messageObj is null creates new miMessage object
* @return miMessage the message object
* @param string $templateName
* @param boolean $isEditable if the form will contain the editable fields/widgets
public function show($templateName, $isEditable)
echo
$this->parse($templateName, $isEditable);
* Called just before the template is parsed
* Subclasses can add custom functionality using this method
* @param miTemplateParser $templateParser the template parser
protected function onParse(miTemplateParser &$templateParser)
* Returns the web form errors handling object
* @return miWebFormErrorsHandler
* Process the form submission
* @return boolean true on success, false if errors were found
$submittedData =
$formField->getData();
$formField->validateData($errors);
// Multiple validators per field
$validator->validate($errors);
return !$errors->hasErrors();
* Returns the submitted data row
* Return the submitted field value
Documentation generated on Thu, 08 May 2008 16:58:01 +0300 by phpDocumentor 1.4.1