/**
  * @return ModelAndView
  **/
 public function run(Prototyped $subject, Form $form, HttpRequest $request)
 {
     if ($object = $form->getValue('id')) {
         FormUtils::object2form($object, $form);
     }
     return ModelAndView::create();
 }
 /**
  * @return ModelAndView
  **/
 public function run(Prototyped $subject, Form $form, HttpRequest $request)
 {
     if (!$form->getErrors()) {
         ClassUtils::copyProperties($form->getValue('id'), $subject);
         FormUtils::form2object($form, $subject, false);
         return parent::run($subject, $form, $request);
     }
     return new ModelAndView();
 }
Example #3
0
File: Input.php Project: werx/forms
 /**
  * @param null $default
  * @param bool $escape
  * @return $this
  */
 public function getValue($default = null, $escape = true)
 {
     // First, see if there is already a value attribute. If so, use it.
     $value = $this->getAttribute('value');
     if (empty($value)) {
         $value = Form::getValue($this->attributes['name'], $default, $escape);
     }
     if ($escape === true) {
         $this->filter($value);
     }
     $this->attribute('value', $value);
     return $this;
 }
 /**
  * @return ModelAndView
  **/
 public function run(Prototyped $subject, Form $form, HttpRequest $request)
 {
     if ($object = $form->getValue('id')) {
         if ($object instanceof Identifiable) {
             $object->dao()->drop($object);
             return ModelAndView::create()->setView(BaseEditor::COMMAND_SUCCEEDED);
         } else {
             // already deleted
             $form->markMissing('id');
         }
     }
     return ModelAndView::create();
 }
Example #5
0
 /**
  * @return $this
  */
 public function isChecked()
 {
     $name = $this->getAttribute('name');
     $values = Form::getValue($name, [], false);
     $item_value = $this->getAttribute('value');
     $type = $this->getAttribute('type');
     if ($type == 'radio') {
         if (!empty($values) && $item_value == $values) {
             $this->checked();
         }
     } elseif ($type == 'checkbox') {
         if (in_array($item_value, (array) $values)) {
             $this->checked();
         }
     }
     return $this;
 }
Example #6
0
 public function testCallback()
 {
     $callback = create_function('&$value,$form', '$value = 42; $form->proof = "it worked!"; return true;');
     $form = new Form(array('field' => array('callback' => $callback)));
     $this->assertTrue($form->validate(array('field' => 1)));
     $this->assertEquals(42, $form->getValue('field'), 'Callback can modify value');
     $this->assertEquals("it worked!", $form->getValue('proof'), 'Callback has access to form object');
     $identical_password_validator = function ($confirmation, $form) {
         return $form->password == $confirmation;
     };
     $form = new Form(array('password' => array('required', 'min_length' => 6), 'password_confirm' => array('required', 'identical' => $identical_password_validator)));
     $this->assertTrue($form->validate(array('password' => 'abcdef', 'password_confirm' => 'abcdef')));
     $this->assertFalse($form->validate(array('password' => 'abcdef', 'password_confirm' => '')));
     $this->assertFalse($form->validate(array('password' => 'abcdef', 'password_confirm' => 'x')));
     // order is important!
     $form = new Form(array('password_confirm' => array('required', 'identical' => $identical_password_validator), 'password' => array('required', 'min_length' => 6)));
     $this->assertFalse($form->validate(array('password' => 'abcdef', 'password_confirm' => 'abcdef')));
     $this->assertFalse($form->validate(array('password' => 'abcdef', 'password_confirm' => '')));
     $this->assertFalse($form->validate(array('password' => 'abcdef', 'password_confirm' => 'x')));
 }
Example #7
0
    <body>
            
    	<div id="wrapper">
            <div id="header">
                <?php 
include_once "engine/templates/header.php";
?>
            </div>
            
    		<div id="content">
                    <form method="post" class="login">
                        <h1>Connexion</h1>
                        <input type="hidden" name="a" value="a3">

                        <input class="input-large" type="text" name="u" placeholder="Pseudo" value="<?php 
echo $form->getValue("u");
?>
" /> 
                                  <?php 
if (@$form->getError("u") != null) {
    echo '<br><span class="input-error">' . $form->getError("u") . "</span>";
}
?>
<br>
                        <input class="input-large" type="password" placeholder="Mot de passe" name="p" value="<?php 
echo $form->getValue("p");
?>
" />
                                  <?php 
if (@$form->getError("p") != null) {
    echo '<br><span class="input-error">' . $form->getError("p") . "</span>";
 public function toValue(Form $form)
 {
     return $form->getValue($this->primitiveName);
 }
Example #9
0
 /**
  * @covers Form::getValue
  */
 public function testGetValue()
 {
     $this->assertNull($this->myForm->getValue('abscent'));
     $this->myForm->setValue('present', 'valeur');
     $this->assertEquals('valeur', $this->myForm->getValue('present'));
 }