protected function defaultEvent($aEvent) { $oForm = new weeForm('myform', 'update'); if (!empty($aEvent['post'])) { $aData = $oForm->filter($aEvent['post']); try { $oForm->validate($aData); // Validation success: process the form doSomething($aData); } catch (FormValidationException $e) { $oForm->fill($aData); $oForm->fillErrors($e); } } $this->set('form', $oForm); }
protected function eventEdit($aEvent) { $oResource = exResourceSet::instance()->fetch($aEvent['get']['r']); $oForm = new weeForm('resource', 'edit'); $oForm->fill($oResource); if (isset($aEvent['post'])) { $aData = $oForm->filter($aEvent['post']); try { $oForm->validate($aData); $oResource->setFromArray($aData); $oResource->update(); $this->update('replaceContent', '#msg', 'The resource has been successfully edited!'); } catch (FormValidationException $e) { $this->update('replaceContent', '#msg', 'The submitted data is erroneous!'); $oForm->fillErrors($e); } $oForm->fill($aData); if (array_value($aEvent, 'context') == 'xmlhttprequest') { $this->update('replace', 'form', $oForm); } } $this->set('form', $oForm); }
<?php // Initialization if (!defined('FORM_PATH')) { define('FORM_PATH', dirname(__FILE__) . '/form/'); } // Test $oForm = new weeForm('mini'); $oForm->fillErrors(array('textbox' => 'Bad')); $oForm->fillErrors(array('textbox' => 'Good')); $this->isMatching('/Good/', $oForm->toString(), _WT("The value given to textbox isn't in the generated form."));
/** Create a simple upload form and handle everything until the file is uploaded. @param $sDest Destination folder for the file. @param $oRenderer Template where the form is shown. @param $oForm Custom form in case the default one isn't enough. */ function upload_form($sDest, $oRenderer, $oForm = null) { if ($oForm === null) { $oForm = new weeForm('weexlib/upload'); } if (!empty($_FILES)) { try { upload_move_to($sDest); $oRenderer['upload_success'] = true; } catch (Exception $e) { $oForm->fillErrors(array('file' => $e->getMessage())); } } $oRenderer['upload_form'] = $oForm; }