本文整理汇总了PHP中Zend\Form\Form::isValid方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::isValid方法的具体用法?PHP Form::isValid怎么用?PHP Form::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Form\Form
的用法示例。
在下文中一共展示了Form::isValid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validate
public function validate($data)
{
$this->form->setData($data);
$isValid = $this->form->isValid();
$normalized = $this->form->getData();
unset($normalized['ViewReportControl']);
$validated = new \SSRS\Form\ValidateResult();
$validated->isValid = $isValid;
$validated->parameters = $normalized;
return $validated;
}
示例2: create
/**
* Create a new image
*
* @param array $data
* @param \Zend\Form\Form $form
* @return bool
*/
public function create($data, &$form)
{
$entity = new ImageEntity();
$em = $this->getEntityManager();
$form->bind($entity);
$form->setData($data);
if (!$form->isValid()) {
return false;
}
// we rename the file with a unique name
$newName = FileUtilService::rename($data['image']['image'], 'images/gallery', "gallery");
foreach (ImageEntity::$thumbnailVariations as $variation) {
$result = FileUtilService::resize($newName, 'images/gallery', $variation["width"], $variation["height"]);
if (!$result) {
$this->message = $result;
return false;
}
}
$entity->setImage($newName);
try {
$em->persist($entity);
$em->flush();
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_CREATED"]);
return true;
} catch (\Exception $e) {
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_IMAGE_NOT_CREATED"]);
return false;
}
}
示例3: create
/**
* Create a new post
*
* @param array $data
* @param \Zend\Form\Form $form
* @return bool
*/
public function create($data, &$form)
{
$post = new PostEntity();
$em = $this->getEntityManager();
$form->bind($post);
$form->setData($data);
if (!$form->isValid()) {
return false;
}
// we rename the file with a unique name
$newName = FileUtilService::rename($data['post']['thumbnail'], 'images/posts', "post");
foreach (PostEntity::$thumbnailVariations as $variation) {
$result = FileUtilService::resize($newName, 'images/posts', $variation["width"], $variation["height"]);
if (!$result) {
$this->message = $result;
return false;
}
}
$post->setThumbnail($newName);
$post->setPostDate("now");
$post->setUrl($this->getPostUrl($post));
try {
$em->persist($post);
$em->flush();
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_CREATED"]);
return true;
} catch (\Exception $e) {
$this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_POST_NOT_CREATED"]);
return false;
}
}
示例4: isValid
public function isValid($data)
{
if (!empty($data['sysmap_id'])) {
$this->_appendParamsSubform($data['sysmap_id']);
}
return parent::isValid($data);
}
示例5: isValid
/**
* Validate the form
*
* @return bool
* @throws Exception\DomainException
*/
public function isValid()
{
$valid = parent::isValid();
/*
* This might seem like a bit of a hack, but this is probably the only way zend framework
* allows us to do this.
*/
foreach ($this->get('fields')->getFieldSets() as $fieldset) {
if ($this->data['language_english']) {
if (!(new NotEmpty())->isValid($fieldset->get('nameEn')->getValue())) {
//TODO: Return error messages
$valid = false;
}
if ($fieldset->get('type')->getValue() === '3' && !(new NotEmpty())->isValid($fieldset->get('optionsEn')->getValue())) {
//TODO: Return error messages
$valid = false;
}
}
if ($this->data['language_dutch']) {
if (!(new NotEmpty())->isValid($fieldset->get('name')->getValue())) {
//TODO: Return error messages
$valid = false;
}
if ($fieldset->get('type')->getValue() === '3' && !(new NotEmpty())->isValid($fieldset->get('options')->getValue())) {
//TODO: Return error messages
$valid = false;
}
}
}
$this->isValid = $valid;
return $valid;
}
示例6: testPreserveEntitiesBoundToCollectionAfterValidation
public function testPreserveEntitiesBoundToCollectionAfterValidation()
{
$this->form->setInputFilter(new \Zend\InputFilter\InputFilter());
$fieldset = new TestAsset\ProductCategoriesFieldset();
$fieldset->setUseAsBaseFieldset(true);
$product = new Entity\Product();
$product->setName('Foobar');
$product->setPrice(100);
$c1 = new Entity\Category();
$c1->setId(1);
$c1->setName('First Category');
$c2 = new Entity\Category();
$c2->setId(2);
$c2->setName('Second Category');
$product->setCategories(array($c1, $c2));
$this->form->add($fieldset);
$this->form->bind($product);
$data = array('product' => array('name' => 'Barbar', 'price' => 200, 'categories' => array(array('name' => 'Something else'), array('name' => 'Totally different'))));
$hash1 = spl_object_hash($this->form->getObject()->getCategory(0));
$this->form->setData($data);
$this->form->isValid();
$hash2 = spl_object_hash($this->form->getObject()->getCategory(0));
// Returned object has to be the same as when binding or properties
// will be lost. (For example entity IDs.)
$this->assertTrue($hash1 == $hash2);
}
示例7: add
/**
* @param \Zend\Form\Form $form
* @param $data
* @return Entity\Comment|null
* @throws \Exception
*/
public function add(\Zend\Form\Form $form, $data)
{
$serviceLocator = $this->getServiceLocator();
$entityManager = $serviceLocator->get('Doctrine\\ORM\\EntityManager');
$entityType = $entityManager->getRepository('\\Comment\\Entity\\EntityType')->findOneByAlias($data['alias']);
if (!$entityType) {
throw new EntityNotFoundException();
}
$form->setData($data);
if ($form->isValid()) {
if ($entityType->getIsEnabled()) {
$data = $form->getData();
$comment = new Entity\Comment();
$comment->setEntityType($entityType);
$user = $serviceLocator->get('Zend\\Authentication\\AuthenticationService')->getIdentity()->getUser();
$comment->setUser($user);
$comment->setComment($data['comment']);
$entityManager->getConnection()->beginTransaction();
try {
$hydrator = new DoctrineHydrator($entityManager);
$hydrator->hydrate($data, $comment);
$entityType->getComments()->add($comment);
$entityManager->persist($comment);
$entityManager->persist($entityType);
$entityManager->flush();
$entityManager->getConnection()->commit();
return $comment;
} catch (\Exception $e) {
$entityManager->getConnection()->rollback();
throw $e;
}
}
}
return null;
}
示例8: isValid
public function isValid($action = null, $currentUserName = null, $currentEmail = null, $editOwn = false)
{
if ($action == 'edit') {
$this->getInputFilter()->get('password_fields')->get('password')->setRequired(false);
}
if (!empty($this->get('password_fields')->get('password')->getValue()) || $action != 'edit') {
$this->getInputFilter()->get('password_fields')->get('password_repeat')->setRequired(true);
}
if ($editOwn) {
$this->getInputFilter()->get('role')->setRequired(false);
}
$userEntityClassName = get_class($this->loggedInUser);
//region attach NoRecordExists validator to the user name
$field = 'uname';
$validatorOptions = array('entityClass' => $userEntityClassName, 'field' => $field);
if ($currentUserName) {
$validatorOptions['exclude'][] = array('field' => $field, 'value' => $currentUserName);
}
$validator = new NoRecordExists($this->entityManager, $validatorOptions);
$this->getInputFilter()->get($field)->getValidatorChain()->attach($validator);
//endregion
//region attach NoRecordExists validator to the email
$field = 'email';
$validatorOptions = array('entityClass' => $userEntityClassName, 'field' => $field);
if ($currentEmail) {
$validatorOptions['exclude'][] = array('field' => $field, 'value' => $currentEmail);
}
$validator = new NoRecordExists($this->entityManager, $validatorOptions);
$this->getInputFilter()->get($field)->getValidatorChain()->attach($validator);
//endregion
return parent::isValid();
}
示例9: isValid
/**
* {@inheritDoc}
*
* Load translation for validators
*/
public function isValid()
{
if ($this->hasValidated) {
return $this->isValid;
}
Pi::service('i18n')->load('validator');
return parent::isValid();
}
示例10: updateAction
public function updateAction()
{
if (!($seo = $this->loadObject($this->seoService, "Seo record doesn't exist."))) {
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
$this->seoForm->bind($seo);
if ($this->request->isPost()) {
$this->seoForm->setData($this->request->getPost());
if ($this->seoForm->isValid()) {
$this->seoService->update($this->seoForm->getData());
$this->flashMessenger()->addSuccessMessage(sprintf('Seo "%s" has been successfully updated.', $seo->getId()));
return $this->redirect()->toRoute('seo', array('action' => 'list'));
}
}
$view = new ViewModel(array('id' => $seo->getId(), 'form' => $this->seoForm));
$view->setTerminal(true);
return $view;
}
示例11: setRegisterForm
public function setRegisterForm(Form $registerForm)
{
$this->registerForm = $registerForm;
$fm = $this->flashMessenger()->setNamespace('zfcuser-register-form')->getMessages();
if (isset($fm[0])) {
$this->registerForm->isValid($fm[0]);
}
return $this;
}
示例12: checkFormIsValid
/**
* Metodo para validar o isPost e isValid
*
* @param Form $form Formulario a ser validado
*
* @return int 0 -> invalid, 1 valid, 2 not isPost
*/
public function checkFormIsValid(Form $form)
{
$objRequest = $this->getRequest();
if ($objRequest->isPost()) {
$form->setData($objRequest->getPost());
return $form->isValid() ? self::CHECK_FORM_IS_VALID : self::CHECK_FORM_IS_NOT_VALID;
} else {
return self::CHECK_FORM_IS_NOT_POST;
}
}
示例13: __invoke
public function __invoke(Form $form)
{
$out = "";
if ($form->hasValidated() && !$form->isValid()) {
$out .= '<div class="alert alert-error">';
$out .= '<strong>Validation problems:</strong> Please check your form input';
$out .= '</div>';
}
return $out;
}
示例14: checkFormIsValid
/**
* Metodo para validar o isPost e isValid
*
* @param Form $form Formulario a ser validado
*
* @return Form
*/
public function checkFormIsValid(Form $form)
{
$objRequest = $this->getRequest();
if ($objRequest->isPost()) {
$form->setData($objRequest->getPost());
if ($form->isValid()) {
return true;
}
}
return false;
}
示例15: login
/**
* @param \Zend\Form\Form $form
* @param $data
* @return bool
*/
public function login(&$form, $data)
{
$user = new User();
$form->bind($user);
$form->setData($data);
if ($form->isValid()) {
return true;
} else {
return false;
}
}