fb1f99137d
A form now always has to be bound, independent of whether the request is a POST request or not. The bind() method detects itself whether the request was a post request or not and reads its data accordingly. The "old" bind()/isBound() methods were renamed to submit()/isSubmitted(). $form = new Form('author'); $form->bind($request, $author); if ($form->isValid()) { // isValid() implies isSubmitted(), non-submitted forms can // never be valid // do something with author now } Alternatively, you can only bind global variables, if you don't have a request object. $form->bindGlobals($author); Note that the $author object is in both cases optional. You can also pass no object at all and read the data using $form->getData(), but then no validation will occur. You can also prefill the form with an object during instantiation. $form = new Form('author', array('data' => $author)); $form->bind($request); // etc.
45 lines
992 B
PHP
45 lines
992 B
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Symfony package.
|
|
*
|
|
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Symfony\Component\Form;
|
|
|
|
/**
|
|
* A field for entering a password.
|
|
*
|
|
* Available options:
|
|
*
|
|
* * always_empty If true, the field will always render empty. Default: true.
|
|
*
|
|
* @see Symfony\Component\Form\TextField
|
|
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
|
*/
|
|
class PasswordField extends TextField
|
|
{
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
protected function configure()
|
|
{
|
|
$this->addOption('always_empty', true);
|
|
|
|
parent::configure();
|
|
}
|
|
|
|
/**
|
|
* {@inheritDoc}
|
|
*/
|
|
public function getDisplayedData()
|
|
{
|
|
return $this->getOption('always_empty') || !$this->isSubmitted()
|
|
? ''
|
|
: parent::getDisplayedData();
|
|
}
|
|
} |