Web Form
miWebForm class manages the web forms used for insert or update operations. Reference to the miWebForm object can be retrieved in action object subclassed from miActionWithWebForm using the getWebForm() method.
* Adding template variables to the web form
<?php
// This adds %%USERID%% and %%USERIMAGEURL%% variables to the template
$form->addMainPageElements(
array(
'%%USERID%%' => $userId,
'%%USERIMAGEURL%%' => $userImageUrl
)
);
?>
<?php
$section = new miTemplateParserSectionInfo('users', $usersNumber, $users)
$form->addTemplateSectionInfo($section);
?>
* Manage validator objects
<?php
$validator = new miValidatorEmail();
$form->addValidator('UserEmail', $validator);
?>
<?php
$form->removeValidators('UserCreditCardNumber');
?>
* Get a field object
<?php
$categories = $form->getFieldObj('CategoryID');
// 'CategoryID' field should be defined as miWebFormFieldSelect in the data manager
$categories->setOptions(
array(
1 => 'Flowers',
2 => 'Trees',
3 => 'Soil'
)
);
?>
* Get/Set data from the web form
<?php
$userType = $form->getFormData('UserType');
switch ($userType)
{
case 1:
$userType = 'Administrator';
break;
default:
$userType = 'Custommer';
}
$form->setFormData('UserType', $userType);
?>
* Change form fields
<?php
$form->setFormFields(
array(
array(
'field' => 'miWebFormWidgetSelect',
'data' => 'CategoryID'
)
)
);
?>
* Display template assigned with the web form
<?php
$form->show('/templates/cart/cart.tmpl', false);
?>