Exemplo n.º 1
1
 public function setData($data)
 {
     if ($data instanceof Traversable) {
         $data = ArrayUtils::iteratorToArray($data);
     }
     $isAts = isset($data['atsEnabled']) && $data['atsEnabled'];
     $isUri = isset($data['uriApply']) && !empty($data['uriApply']);
     $email = isset($data['contactEmail']) ? $data['contactEmail'] : '';
     if ($isAts && $isUri) {
         $data['atsMode']['mode'] = 'uri';
         $data['atsMode']['uri'] = $data['uriApply'];
         $uri = new Http($data['uriApply']);
         if ($uri->getHost() == $this->host) {
             $data['atsMode']['mode'] = 'intern';
         }
     } elseif ($isAts && !$isUri) {
         $data['atsMode']['mode'] = 'intern';
     } elseif (!$isAts && !empty($email)) {
         $data['atsMode']['mode'] = 'email';
         $data['atsMode']['email'] = $email;
     } else {
         $data['atsMode']['mode'] = 'none';
     }
     if (!array_key_exists('job', $data)) {
         $data = array('job' => $data);
     }
     return parent::setData($data);
 }
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
 /**
  * @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;
 }
Exemplo n.º 4
0
 /**
  * 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;
     }
 }
Exemplo n.º 5
0
 /**
  * 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;
     }
 }
Exemplo n.º 6
0
 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);
 }
 public function setData($data)
 {
     $parsedData = $data;
     if ($data instanceof AbstractSiteOptions) {
         $parsedData = array('config' => $data->toArray());
     }
     return parent::setData($parsedData);
 }
Exemplo n.º 8
0
 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;
 }
 /**
  * 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;
     }
 }
Exemplo n.º 10
0
 /**
  * @param array|\ArrayAccess|\Traversable $data
  * @return Form
  */
 public function setData($data)
 {
     //Set default values
     foreach ($this->getDefaults() as $index => $value) {
         if (!isset($data[$index])) {
             $data[$index] = $value;
         }
     }
     return parent::setData($data);
 }
Exemplo n.º 11
0
 public function setData($data)
 {
     if ($data instanceof Traversable) {
         $data = ArrayUtils::iteratorToArray($data);
     }
     if (!array_key_exists('job', $data)) {
         $data = array('job' => $data);
     }
     return parent::setData($data);
 }
Exemplo n.º 12
0
 /**
  * @param  Params                          $params
  * @param  Form                            $form
  * @param  \FzyAuth\Service\Password\Reset $reset
  * @return \Zend\Http\Response|ViewModel
  */
 protected function preReset(Params $params, Form $form, \FzyAuth\Service\Password\Reset $reset)
 {
     if (!trim($params->get('token')) || $reset->getUserByToken($params->get('token'))->isNull()) {
         return $this->redirect()->toRoute(UserController::ROUTE_LOGIN);
     }
     $form->setData($params->get());
     $view = new ViewModel(array('changePasswordForm' => $form));
     $view->setTemplate('fzy-auth/password/reset');
     return $view;
 }
Exemplo n.º 13
0
 /**
  * @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;
     }
 }
 /**
  * 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;
 }
Exemplo n.º 15
0
 public function saveAction(Request $request, Create $createService, Form $form, View $view, Redirect $redirect)
 {
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $createService->create($form->getData());
             return $redirect->toRoute('admin-translate-words');
         }
     }
     $view->setForm($form);
     $view->setTemplate('translate/admin/word/edit');
     return $view;
 }
Exemplo n.º 16
0
 public function testPrepareBindDataAllowsFilterToConvertStringToArray()
 {
     $data = array('foo' => '1,2');
     $filteredData = array('foo' => array(1, 2));
     $element = new TestAsset\ElementWithStringToArrayFilter('foo');
     $hydrator = $this->getMock('Zend\\Stdlib\\Hydrator\\ArraySerializable');
     $hydrator->expects($this->any())->method('hydrate')->with($filteredData, $this->anything());
     $this->form->add($element);
     $this->form->setHydrator($hydrator);
     $this->form->setObject(new stdClass());
     $this->form->setData($data);
     $this->form->bindValues($data);
 }
Exemplo n.º 17
0
 /**
  * @param $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     if (!empty($data['setting']['aboutProfileImage']['name'])) {
         if (!($newName = FileUtilService::rename($data['setting']['aboutProfileImage'], 'images', null, "about-profile"))) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         } else {
             FileUtilService::resize($newName, 'images', 400, null, 'png');
             FileUtilService::deleteFile(ROOT_PATH . '/images/' . $newName);
         }
     }
     if (!empty($data['setting']['homeImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['homeImage'], 'images', null, "home-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['aboutImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['aboutImage'], 'images', null, "about-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['galleriesImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['galleriesImage'], 'images', null, "galleries-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['servicesImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['servicesImage'], 'images', null, "services-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     if (!empty($data['setting']['contactImage']['name'])) {
         if (!FileUtilService::rename($data['setting']['contactImage'], 'images', null, "contact-side-bg")) {
             $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_NOT_CREATED"]);
             return false;
         }
     }
     $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_SETTINGS_UPDATED"]);
     return true;
 }
Exemplo n.º 18
0
 public function setData($data)
 {
     parent::setData($data);
     $pluginClasses = $this->getAttribute(static::SET_DATA_PLUGIN_CLASSES);
     if (!empty($pluginClasses)) {
         if (!is_array($pluginClasses)) {
             throw new \InvalidArgumentException('The plugin classes attribute must be an array');
         }
         foreach ($pluginClasses as $pluginClass) {
             if (!is_subclass_of($pluginClass, '\\Zork\\Form\\Plugin\\SetDataInterface')) {
                 throw new \InvalidArgumentException('The plugin class must be implement \\Zork\\Form\\Plugin\\SetDataInterface');
             }
             $plugin = new $pluginClass();
             $plugin->setData($this, $data);
         }
     }
     return $this;
 }
Exemplo n.º 19
0
 public function testCorrectlyHydrateBaseFieldsetWhenHydratorThatDoesNotIgnoreInvalidDataIsUsed()
 {
     $fieldset = new Fieldset('example');
     $fieldset->add(array('name' => 'foo'));
     // Add an hydrator that ignores if values does not exist in the
     $fieldset->setObject(new Entity\SimplePublicProperty());
     $fieldset->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
     $this->form->add($fieldset);
     $this->form->setBaseFieldset($fieldset);
     $this->form->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty());
     // Add some inputs that do not belong to the base fieldset
     $this->form->add(array('type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit'));
     $object = new Entity\SimplePublicProperty();
     $this->form->bind($object);
     $this->form->setData(array('submit' => 'Confirm', 'example' => array('foo' => 'value example')));
     $this->assertTrue($this->form->isValid());
     // Make sure the object was not hydrated at the "form level"
     $this->assertFalse(isset($object->submit));
 }
Exemplo n.º 20
0
 /**
  * {@inheritdoc}
  *
  * @param \Dms\Document\Document $document
  *
  * @see \Dms\Storage\StorageInterface::write()
  */
 public function write(\Dms\Document\Document $document)
 {
     $ret = null;
     $name = $document->getId();
     $nameMod = substr($name, 4);
     $f = substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/';
     $path = $this->getBasePath() . $f;
     if (!is_dir($path)) {
         mkdir($path, 0777, true);
     }
     $p = $path . $nameMod . '.dat';
     if ($document->getSupport() === Document::SUPPORT_FILE_MULTI_PART_STR) {
         $fileInput = new FileInput(key($document->getDatas()));
         $fileInput->getFilterChain()->attachByName('filerenameupload', ['target' => $p]);
         $inputFilter = new InputFilter();
         $inputFilter->add($fileInput);
         $form = new Form();
         $form->setInputFilter($inputFilter);
         $form->setData($document->getDatas());
         if ($form->isValid()) {
             $form->getData();
         }
     } else {
         $fp = fopen($p, 'w');
         fwrite($fp, $document->getDatas());
         $document->setWeight(strlen($document->getDatas()));
         fclose($fp);
     }
     $conf_storage = $this->options->getStorage();
     if (isset($conf_storage['name']) && $conf_storage['name'] === 's3') {
         print_r($_FILES);
         $this->s3Client->copyObject(['Bucket' => $conf_storage['bucket'], 'Key' => $f . $nameMod . '.dat', 'CopySource' => $conf_storage['bucket'] . '/' . $f . $nameMod . '.dat', 'ContentType' => $document->getType(), 'ContentDisposition' => sprintf('filename=%s', null === $document->getName() ? substr($file, -1 * strlen($document->getFormat())) === $document->getFormat() ? $file : $file . '.' . $document->getFormat() : $document->getName()), 'MetadataDirective' => 'REPLACE']);
     }
     $document->setSupport(Document::SUPPORT_FILE_STR);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . '.dat', 'support' => $document->getSupport(), 'name' => $name));
     $serialize = serialize($document);
     $fp = fopen($path . $nameMod . '.inf', 'w');
     $ret += fwrite($fp, $serialize);
     fclose($fp);
     $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . 'inf', 'support' => $document->getSupport(), 'name' => $name));
     return $ret;
 }
Exemplo n.º 21
0
 /**
  * Create a new gallery
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create(&$data, &$form)
 {
     $entity = new GalleryEntity();
     $em = $this->getEntityManager();
     if (isset($data['gallery']['images'])) {
         $data['gallery']['images'] = json_decode($data['gallery']['images'], true);
     }
     $form->bind($entity);
     $form->setData($data);
     $form->setBindOnValidate(Form::BIND_MANUAL);
     if (!$form->isValid()) {
         return false;
     }
     $entity->setName($data['gallery']['name']);
     $entity->setUrl($this->getGalleryUrl($entity));
     if (isset($data['gallery']['parentGallery']) && !empty($data['gallery']['parentGallery'])) {
         $parent = $this->getGalleryRepository()->find($data['gallery']['parentGallery']);
         if ($parent) {
             $entity->setParentGallery($parent);
         }
     }
     // WHY THE F**K DO I HAVE TO FLUSH HERE
     $em->persist($entity);
     $em->flush();
     foreach ($data['gallery']['images'] as $join) {
         $image = $this->getImageRepository()->find($join['joinId']);
         if ($image) {
             $galleryImage = new GalleryImage($join['title'], $join['position']);
             $image->addGalleries($galleryImage);
             $entity->addImages($galleryImage);
         }
     }
     try {
         $em->persist($entity);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_GALLERY_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_GALLERY_NOT_CREATED"]);
         return false;
     }
 }
Exemplo n.º 22
0
 /**
  * Create a new user
  *
  * @param array $data
  * @param \Zend\Form\Form $form
  * @return bool
  */
 public function create($data, &$form)
 {
     $user = new UserEntity();
     $em = $this->getEntityManager();
     $form->bind($user);
     $form->setData($data);
     if (!$form->isValid()) {
         return false;
     }
     $user->setPassword(UserEntity::hashPassword($user->getPassword()));
     try {
         $em->persist($user);
         $em->flush();
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_USER_CREATED"]);
         return true;
     } catch (\Exception $e) {
         $this->message = $this->getTranslator()->translate($this->getVocabulary()["MESSAGE_USER_NOT_CREATED"]);
         return false;
     }
 }
Exemplo n.º 23
0
 /**
  * @param \Phpro\SmartCrud\Gateway\CrudGatewayInterface $gateway
  * @param \Zend\EventManager\EventManager               $eventManager
  * @param \Zend\Form\Form                               $form
  * @param \Phpro\SmartCrud\Service\SmartServiceResult   $result
  */
 public function it_should_handle_no_data($gateway, $eventManager, $form, $result)
 {
     $entity = new \StdClass();
     $gateway->loadEntity('entityKey', null)->shouldBecalled()->willReturn($entity);
     $gateway->create(Argument::any(), Argument::any())->shouldNotBeCalled();
     $form->hasValidated()->shouldBeCalled()->willreturn(false);
     $form->bind(Argument::any())->shouldBeCalled();
     $form->bindOnValidate()->shouldBeCalled();
     $form->setData(Argument::any())->shouldNotBeCalled();
     $form->isValid()->shouldNotBeCalled();
     $this->setEntityKey('entityKey');
     $this->setGateway($gateway);
     $this->setForm($form);
     $this->run(null, null)->shouldReturnAnInstanceOf('Phpro\\SmartCrud\\Service\\SmartServiceResult');
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_HYDRATION))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_DATA_VALIDATION))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::INVALID_CREATE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::BEFORE_CREATE))->shouldNotBeCalled();
     $eventManager->trigger(Argument::which('getName', CrudEvent::AFTER_CREATE))->shouldNotBeCalled();
 }
 /**
  * Process form
  * 
  * @return Response|null
  */
 public function processForm()
 {
     $request = $this->getRequest();
     $this->form->setData($request->getPost());
     $fm = $this->flashMessenger();
     if (!$this->form->isValid()) {
         $fm->addErrorMessage('The form was not valid. ' . var_export($this->form->getMessages(), true), 'error');
         return;
     }
     try {
         $object = $this->saveObject();
     } catch (\Exception $exception) {
     }
     if (isset($exception)) {
         $fm->addErrorMessage('The object was not saved. ' . $exception->getMessage());
         return;
     } else {
         $fm->addSuccessMessage('The object has been successfully saved!');
     }
     return $this->redirectTo($object);
 }
 protected function processForm(Form $form, $options = array(), $extra1 = null, $extra2 = array())
 {
     /**
      * Special case for a simpler API: if the second argument is a string, it is used as the route to redirect
      * to, the third argument as the route parameters and the fourth argument as additional options.
      */
     if (is_string($options)) {
         $options = array('redirect_route' => $options, 'redirect_params' => $extra1);
         $options = $options + $extra2;
     }
     if ($options && isset($options['object_manager'])) {
         $objectManager = $options['object_manager'];
     } else {
         $objectManager = $this->getEntityManager();
     }
     /** @var $request Request */
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $form->bindValues();
             $objectManager->persist($form->getObject());
             $objectManager->flush();
             if (!empty($options['success_message'])) {
                 $this->flashMessenger()->addMessage($options['success_message']);
             }
             if (!empty($options['redirect_route'])) {
                 $params = array();
                 if (!empty($options['redirect_params'])) {
                     $params = $options['redirect_params'];
                     if (is_callable($params)) {
                         $params = call_user_func($params, $form);
                     }
                 }
                 return $this->redirect()->toRoute($options['redirect_route'], $params);
             }
         }
     }
     return null;
 }
Exemplo n.º 26
0
 public function formAction()
 {
     // Build a name element.
     $name = new Element('name');
     $name->setLabel('Your name');
     $name->setAttributes(array('type' => 'text'));
     // Build a submit button element.
     $send = new Element('send');
     $send->setLabel('Send');
     $send->setAttributes(array('type' => 'submit', 'value' => 'Send'));
     // Build a checkbox element.
     $check = new Checkbox('check');
     $check->setLabel('Checkbox example');
     // Build a multi-checkbox element.
     $multicheck = new MultiCheckbox('multicheck');
     $multicheck->setLabel('Multi checkbox example');
     $multicheck->setOptions(array('value_options' => array('One' => 'one', 'Two' => 'two')));
     // Assemble the form.
     $form = new Form('contact');
     $form->add($name);
     $form->add($check);
     $form->add($multicheck);
     $form->add($send);
     // Get the request if any.
     $request = $this->getRequest();
     $data = $request->getPost();
     $form->setData($data);
     // Validate the form
     if ($form->isValid()) {
         $validatedData = $form->getData();
         $success = 'Form submit was successful';
     } else {
         $success = 'Form submit failed';
         $messages = $form->getMessages();
     }
     // Set the method attribute for the form
     $form->setAttribute('method', 'post');
     return new ViewModel(array('form' => $form, 'success' => $success, 'messages' => $messages, 'data' => $data));
 }
Exemplo n.º 27
0
 public function saveAction(Params $params, Request $request, Response $response, Form $form, Finder $finderService, Update $updateService, Form $form, View $view)
 {
     if ($request->getMethod() !== Request::METHOD_PUT) {
         return $view;
     }
     $id = $params('id');
     $entity = $finderService->find(['T4webTranslate' => ['Words' => ['Id' => (int) $id]]]);
     if (!$entity) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors(['message' => 'bad params']);
         return $view;
     }
     $data = Json::decode($request->getContent(), Json::TYPE_ARRAY);
     $form->setData($data);
     if (!$form->isValid()) {
         $response->setStatusCode(Response::STATUS_CODE_404);
         $view->setErrors($form->getMessages());
         return $view;
     }
     $entity->populate($data);
     $result = $updateService->update($id, $entity->extract());
     $view->setVariables($result->extract());
     return $view;
 }
Exemplo n.º 28
0
 public function testBindEmptyValue()
 {
     $value = new \ArrayObject(array('foo' => 'abc', 'bar' => 'def'));
     $inputFilter = new InputFilter();
     $inputFilter->add(array('name' => 'foo', 'required' => false));
     $inputFilter->add(array('name' => 'bar', 'required' => false));
     $form = new Form();
     $form->add(new Element('foo'));
     $form->add(new Element('bar'));
     $form->setInputFilter($inputFilter);
     $form->bind($value);
     $form->setData(array('foo' => '', 'bar' => 'ghi'));
     $form->isValid();
     $this->assertSame('', $value['foo']);
     $this->assertSame('ghi', $value['bar']);
 }
Exemplo n.º 29
0
 /**
  * Verarbeitet das Formular zum Erstellen eines Nodes.
  *
  * @param \Zend\Form\Form $form            
  * @return \Zend\Http\PhpEnvironment\Response|boolean
  */
 public function processNodeForm(\Zend\Form\Form $form)
 {
     $prg = $this->getServiceLocator()->get('controllerpluginmanager')->get('prg')->__invoke();
     if ($prg instanceof \Zend\Http\PhpEnvironment\Response) {
         return $prg;
     } elseif (true === is_array($prg)) {
         $form->setData($prg);
         if (true == $form->isValid()) {
             $node = $form->getData();
             $this->saveNode($node);
             return true;
         }
     }
     return false;
 }
Exemplo n.º 30
0
 public function setData($data)
 {
     $this->filter = null;
     return parent::setData($data);
 }