コード例 #1
0
ファイル: Validator.php プロジェクト: realholgi/formobject
 protected function parseMessage($msgKey)
 {
     $regMessages = Registry::messages();
     if (!is_array($regMessages)) {
         $regMessages = array();
     }
     if (isset($regMessages[$msgKey])) {
         $msg = $regMessages[$msgKey];
     } else {
         $myMessages = static::collectMsgTemplates();
         $msg = $myMessages[$msgKey];
     }
     $vars = $this->getMessageVars();
     return str_replace(array_keys($vars), array_values($vars), $msg);
 }
コード例 #2
0
error_reporting(E_ALL);
require_once "lib/AutoLoader.php";
use FormObject\Registry;
use FormObject\Renderer;
use FormObject\Form;
use FormObject\Field;
use FormObject\Field\TextField;
use FormObject\Field\Action;
use FormObject\Field\CheckboxField;
use FormObject\Field\BooleanRadioField;
use FormObject\Validator\SimpleValidator;
use FormObject\Validator\TextValidator;
use FormObject\Validator\BooleanValidator;
use FormObject\Validator\RequiredValidator;
use Illuminate\Validation\Validator;
Registry::getRenderer()->addPath(dirname(__FILE__) . '/themes/bootstrap/templates/forms');
/**
 * @brief ...
 * @var \FormObject\Form
 */
$form = Form::create();
$form->push(TextField::create('name')->setTitle('Please enter your name')->setValue('Billy'), TextField::create('surname')->setTitle('Please enter your surname')->setValue('Talent'), CheckboxField::create('rememberMe')->setTitle('Remember Me'), BooleanRadioField::create('rememberMyRadio')->setTitle('Remember my radio')->setStringForTrue('Remember my radio')->setStringForFalse('Forget my radio')->setValue(TRUE), TextField::create('message')->setTitle('Message')->setValue('')->setMultiLine(TRUE));
$nameValidator = new TextValidator();
$nameValidator->required = FALSE;
$nameValidator->minLength = 3;
$nameValidator->setMaxLength = 12;
$surnameValidator = new RequiredValidator();
$surnameValidator->required = TRUE;
$requiredValidator = new BooleanValidator();
$requiredValidator->mustBeTrue = TRUE;
$validator = new SimpleValidator($form);