Hello. I'm trying to create a simple form that stores the user. However, some fields have to be optional. Their values can be empty. Nevertheless phalcon form use PresenceOf validator with 'allowEmpty' => false, by default. I dont know how to remove this validator. I can only add new one.
So, can you help me? How to create optional element in phalcon form? What I am doing wrong?
class UserForm extends Form {
public function initialize($entity = null, $options = array()) { $this->setValidation(array( 'notNullValidations' => false )); if (!isset($options['edit']) && !isset($options['add'])){ $element = new Text("id"); $this->add($element->setLabel("Id")); } else $this->add(new Hidden("id")); $email = new Text("email", array('id' => 'userEmail')); $email->setLabel("Email"); $email->setFilters(array('striptags', 'string')); $email->addValidators( array( new PresenceOf( array( 'message' => 'Email обязательно' ) ) ) ); $this->add($email); $this->add(new TextArea('admin_comment', array('id'=>'userComment'))); $lastname = new Text('lastname', array('id' => 'fUser')); $this->add(new Text('firstname', array('id' => 'iUser'))); $this->add($lastname); $this->add(new Text('patronymic', array('id' => 'oUser'))); $this->add(new Numeric('phone', array('id' => 'telFaxUser'))); if (isset($options['add'])) { $password = new Password('password'); $password->setLabel("Пароль"); $password->setFilters(array('striptags', 'string')); $password->addValidators( array( new PresenceOf( array( 'message' => 'пароль обязательно' ) ) ) ); $this->add($password); } $this->add( new Select( "status", array( '1' => 'Активный', '0' => 'Заблокированый' ) ) ); }
}