예제 #1
0
 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);
 }
예제 #2
0
 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);
 }
예제 #3
0
파일: options.php 프로젝트: extend/wee
<?php

// Initialization
if (!defined('FORM_PATH')) {
    define('FORM_PATH', dirname(__FILE__) . '/form/');
}
// Test
$oForm = new weeForm('options', 'update');
$oHelper = $oForm->helper('weeFormOptionsHelper', 'choice');
$aOptions = array(array('label' => 'test 1', 'value' => '39'), array('label' => 'test 2', 'value' => '40'), array('label' => 'test 3', 'value' => '41'), array('label' => 'test 4', 'value' => '43'), array('name' => 'group', 'children' => array(array('label' => 'test 5', 'value' => '44'))));
$oHelper->addOptions($aOptions);
$oDupeHelper = $oForm->helper('weeFormOptionsHelper', 'dupe');
$oDupeHelper->addOptions($aOptions);
try {
    $oForm->validate(array('choice' => 42));
    $this->fail(_WT('Form validation should have failed.'));
} catch (FormValidationException $e) {
}
$oHelper->addOption(array('label' => 'test 42', 'value' => '42'));
try {
    $oForm->validate(array('choice' => 42));
} catch (FormValidationException $e) {
    $this->fail(_WT('Form validation should have succeeded.'));
}
$oHelper->select('39');
$this->isTrue($oHelper->isSelected(39), _WT('Only 39 should have been selected.'));
$this->isFalse($oHelper->isSelected(40), _WT('Only 39 should have been selected.'));
$this->isFalse($oHelper->isSelected(41), _WT('Only 39 should have been selected.'));
$this->isFalse($oHelper->isSelected(42), _WT('Only 39 should have been selected.'));
$this->isFalse($oHelper->isSelected(43), _WT('Only 39 should have been selected.'));
$this->isFalse($oHelper->isSelected(44), _WT('Only 39 should have been selected.'));
예제 #4
0
파일: validate.php 프로젝트: extend/wee
<?php

// Initialization
if (!defined('FORM_PATH')) {
    define('FORM_PATH', dirname(__FILE__) . '/form/');
}
// Test
$oForm = new weeForm('mini', 'update');
$aPost = array('hidden' => 42, 'textbox' => 'error');
try {
    $oForm->validate($aPost);
    $this->fail(_WT('Form validation should have failed.'));
} catch (FormValidationException $e) {
}
예제 #5
0
파일: required.php 프로젝트: extend/wee
<?php

// Initialization
if (!defined('FORM_PATH')) {
    define('FORM_PATH', dirname(__FILE__) . '/form/');
}
// Test
$oForm = new weeForm('required');
try {
    $oForm->validate(array());
    $this->fail(_WT('Form validation should have failed.'));
} catch (FormValidationException $e) {
}
try {
    $oForm->validate(array('textbox' => 'testing'));
    $this->fail(_WT('Form validation should have failed.'));
} catch (FormValidationException $e) {
}
try {
    $oForm->validate(array('checklist' => array()));
    $this->fail(_WT('Form validation should have failed.'));
} catch (FormValidationException $e) {
}
try {
    $oForm->validate(array('textbox' => 'testing', 'checklist' => array()));
    $this->fail(_WT('Form validation should have failed.'));
} catch (FormValidationException $e) {
}
try {
    $oForm->validate(array('textbox' => 'testing', 'checklist' => array(0 => 0)));
} catch (FormValidationException $e) {