Development

Changeset 6608

You must first sign up to be able to contribute.

Changeset 6608

Show
Ignore:
Timestamp:
12/20/07 13:45:50 (9 months ago)
Author:
fabien
Message:

added sfForm::getValue()

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/form/sfForm.class.php

    r6326 r6608  
    173173 
    174174  /** 
     175   * Returns a cleaned value by field name. 
     176   * 
     177   * If the form is not bound, it will return null. 
     178   * 
     179   * @param  string  The name of the value required 
     180   * @return string  The cleaned value 
     181   */ 
     182  public function getValue($field) 
     183  { 
     184    return $this->isBound ? $this->values[$field] : null; 
     185  } 
     186 
     187  /** 
    175188   * Gets the error schema associated with the form. 
    176189   * 
  • branches/1.1/test/unit/form/sfFormTest.php

    r6326 r6608  
    1111require_once(dirname(__FILE__).'/../../bootstrap/unit.php'); 
    1212 
    13 $t = new lime_test(58, new lime_output_color()); 
     13$t = new lime_test(60, new lime_output_color()); 
    1414 
    1515class FormTest extends sfForm 
     
    143143} 
    144144 
    145 // ->bind() ->isValid() ->getValues() ->isBound() ->getErrorSchema() 
     145// ->bind() ->isValid() ->getValues() ->getValue() ->isBound() ->getErrorSchema() 
    146146$t->diag('->bind() ->isValid() ->getValues() ->isBound() ->getErrorSchema()'); 
    147147$f = new FormTest(); 
     
    158158$t->ok(!$f->isValid(), '->isValid() returns false if the form is not bound'); 
    159159 
     160$t->is($f->getValue('first_name'), null, '->getValue() returns null if the form is not bound'); 
    160161$f->bind(array('first_name' => 'Fabien', 'last_name' => 'Potencier')); 
    161162$t->ok($f->isBound(), '->isBound() returns true if the form is bound'); 
    162163$t->is($f->getValues(), array('first_name' => 'Fabien', 'last_name' => 'Potencier'), '->getValues() returns an array of cleaned values if the form is bound'); 
    163164$t->ok($f->isValid(), '->isValid() returns true if the form passes the validation'); 
     165$t->is($f->getValue('first_name'), 'Fabien', '->getValue() returns the cleaned value for a field name if the form is bound'); 
    164166 
    165167$f->bind(array());