/**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $formData = $this->form->getData();
         $name = (string) $formData->getName();
         if ($name) {
             $this->qb->andWhere($this->qb->expr()->like('p.name', ':name'))->setParameter('name', '%' . $name . '%');
         }
         $text = (string) $formData->getText();
         if ($text) {
             $this->qb->andWhere($this->qb->expr()->orx($this->qb->expr()->like('p.intro', ':intro'), $this->qb->expr()->like('p.content', ':content')))->setParameter('intro', '%' . $text . '%')->setParameter('content', '%' . $text . '%');
         }
         $isPublished = (string) $formData->getIsPublished();
         if ($isPublished) {
             if ($isPublished == 'yes') {
                 $this->qb->andWhere($this->qb->expr()->eq('p.status', ':status'))->setParameter('status', PostStatus::PUBLISHED);
             }
             if ($isPublished == 'no') {
                 $this->qb->andWhere($this->qb->expr()->neq('p.status', ':status'))->setParameter('status', PostStatus::PUBLISHED);
             }
         }
         $order = (string) $formData->getOrder();
         if ($order) {
             $this->qb->orderBy('p.' . $order, 'DESC');
         }
         return true;
     }
     return false;
 }
Example #2
0
 public function testValid()
 {
     $this->sut->submit(['fullName' => 'James T. Kirk', 'location' => 'San Francisco', 'placeOfBirth' => 'Iowa']);
     foreach ($this->sut as $name => $child) {
         $this->assertTrue($child->isValid(), $name);
     }
     $this->assertTrue($this->sut->isValid());
 }
Example #3
0
 /**
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $query = $this->form->getData()->getQuery();
         return true;
     }
     return false;
 }
Example #4
0
 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $this->entity = $this->form->getData();
         $this->em->persist($this->entity);
         $this->em->flush();
         return true;
     }
     return false;
 }
 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $formData = $this->form->getData();
         if ($name = (string) $formData->name) {
             $this->qb->andWhere($this->qb->expr()->like('t.name', ':name'))->setParameter('name', '%' . $name . '%');
         }
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $entityModel = $this->form->getData();
         $this->entity->setContent($this->sanitizer->doClean($entityModel->getContent()));
         $this->entity->setUserName($this->sanitizer->doClean($entityModel->getUserName()));
         $this->entity->setUserEmail($this->sanitizer->doClean($entityModel->getUserEmail()));
         $this->entity->setUserWeb($this->sanitizer->doClean($entityModel->getUserWeb()));
         $this->em->persist($this->entity);
         $this->em->flush();
         return true;
     }
     return false;
 }
Example #7
0
 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $entityModel = $this->form->getData();
         $file = $entityModel->getFile();
         $fileName = $this->getName() . '.' . $file->getClientOriginalExtension();
         $file->move($this->uploadPath, $fileName);
         $this->entity->setFile($fileName);
         $this->em->persist($this->entity);
         $this->em->flush();
         return true;
     }
     return false;
 }
 /**
  * @param UserInterface $user
  *
  * @return bool
  */
 public function process(UserInterface $user)
 {
     $this->form->setData($user);
     if ('POST' == $this->request->getMethod()) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($user);
             return true;
         }
         // Reloads the user to reset its username. This is needed when the
         // username or password have been changed to avoid issues with the
         // security layer.
         $this->userManager->reloadUser($user);
     }
     return false;
 }
 private function handleForm(Request $request, Form $form, $id, $command)
 {
     $form->submit($request);
     if ($form->isValid()) {
         $this->handleCommand($command);
         return $this->redirectView($this->router->generate('get_game', array('id' => $id)), Codes::HTTP_CREATED);
     }
     return $form;
 }
Example #10
0
 /**
  * @param Request $request
  * @param Form $form
  */
 protected function processForm(Request $request, Form $form)
 {
     $data = json_decode($request->getContent(), true);
     if ($data === null) {
         $apiProblem = new ApiProblem(Response::HTTP_BAD_REQUEST, ApiProblem::TYPE_INVALID_REQUEST_BODY_FORMAT);
         throw new ApiProblemException($apiProblem);
     }
     $clearMissing = $request->getMethod() !== 'PATCH';
     $form->submit($data, $clearMissing);
 }
 /**
  * Process current form
  * @return boolean
  */
 public function process()
 {
     $success = false;
     if ($this->request->getMethod() == 'POST' || $this->request->getMethod() == 'PUT') {
         // Correct HTTP method => try to process form
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             // Form is valid => create or update the path
             $this->data = $this->form->getData();
             if ($this->request->getMethod() == 'POST') {
                 // Create path
                 $success = $this->create();
             } else {
                 // Edit existing path
                 $success = $this->edit();
             }
         }
     }
     return $success;
 }
 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $formData = $this->form->getData();
         if ($name = (string) $formData->name) {
             $this->qb->andWhere($this->qb->expr()->like('l.name', ':name'))->setParameter('name', '%' . $name . '%');
         }
         if ($isPublished = (string) $formData->isPublished) {
             if ($isPublished == 'yes') {
                 $this->qb->andWhere($this->qb->expr()->like('l.isPublished', ':isPublished'))->setParameter('isPublished', 1);
             }
             if ($isPublished == 'no') {
                 $this->qb->andWhere($this->qb->expr()->like('l.isPublished', ':isPublished'))->setParameter('isPublished', 0);
             }
         }
         return true;
     }
     return false;
 }
Example #13
0
File: Image.php Project: fire1/liby
 /**
  * Listen privet form
  * @param Request $request
  * @return bool
  */
 private function eventListener(Request $request)
 {
     $this->rq = $request;
     if ($request->isMethod("post")) {
         $this->form->submit($this->rq);
         if ($this->rq->isXmlHttpRequest()) {
             $this->ajax = true;
         }
         return true;
     }
     return false;
 }
Example #14
0
 /**
  * validate
  *
  * @param Form    $form    Form
  * @param Request $request Request
  *
  * @return boolean
  */
 public function validate(Form $form, Request $request)
 {
     if ($this->hasMethod($request->getMethod())) {
         if ($request->getMethod() != 'POST') {
             $form->submit($request);
         } else {
             $form->handleRequest($request);
         }
         return $form->isValid();
     }
     return false;
 }
 public function testDataIsInitializedFromSubmit()
 {
     $mock = $this->getMockBuilder('\\stdClass')->setMethods(array('preSetData', 'preSubmit'))->getMock();
     $mock->expects($this->at(0))->method('preSetData');
     $mock->expects($this->at(1))->method('preSubmit');
     $config = new FormConfigBuilder('name', null, $this->dispatcher);
     $config->addEventListener(FormEvents::PRE_SET_DATA, array($mock, 'preSetData'));
     $config->addEventListener(FormEvents::PRE_SUBMIT, array($mock, 'preSubmit'));
     $form = new Form($config);
     // no call to setData() or similar where the object would be
     // initialized otherwise
     $form->submit('foobar');
 }
Example #16
0
 public function testFalseIsConvertedToNull()
 {
     $mock = $this->getMockBuilder('\\stdClass')->setMethods(array('preBind'))->getMock();
     $mock->expects($this->once())->method('preBind')->with($this->callback(function ($event) {
         return null === $event->getData();
     }));
     $config = new FormConfigBuilder('name', null, $this->dispatcher);
     $config->addEventListener(FormEvents::PRE_SUBMIT, array($mock, 'preBind'));
     $form = new Form($config);
     $form->submit(false);
     $this->assertTrue($form->isValid());
     $this->assertNull($form->getData());
 }
 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $formData = $this->form->getData();
         if ($text = (string) $formData->text) {
             $this->qb->andWhere($this->qb->expr()->like('c.content', ':text'))->setParameter('text', '%' . $text . '%');
         }
         if ($status = (string) $formData->status) {
             if ($status == 'pending') {
                 $this->qb->andWhere($this->qb->expr()->like('c.status', ':status'))->setParameter('status', 0);
             }
             if ($status == 'yes') {
                 $this->qb->andWhere($this->qb->expr()->like('c.status', ':status'))->setParameter('status', 1);
             }
             if ($status == 'no') {
                 $this->qb->andWhere($this->qb->expr()->like('c.status', ':status'))->setParameter('status', 2);
             }
         }
         return true;
     }
     return false;
 }
Example #18
0
 /**
  *
  * @return boolean
  */
 public function process()
 {
     $this->form->submit($this->request);
     if ($this->form->isValid()) {
         $entityModel = $this->form->getData();
         $this->entity->setName((string) $entityModel->getName());
         $this->entity->setIntro((string) $entityModel->getIntro());
         $this->entity->setContent((string) $entityModel->getContent());
         $this->entity->setImage((string) $entityModel->getImage());
         $this->entity->setStatus((bool) $entityModel->getStatus());
         $valid = true;
         if ($this->container !== null) {
             /** @var $validatorService \Symfony\Component\Validator\Validator */
             $validatorService = $this->container->get('validator');
             /** @var $errors \Symfony\Component\Validator\ConstraintViolationList */
             $errors = $validatorService->validate($this->entity, array());
             $valid = $errors->count() === 0;
         }
         if ($valid) {
             if ($this->entity->isPublished() && !$this->entity->getPublishedAt()) {
                 $this->entity->setPublishedAt(new DateTime());
             }
             $this->entity->removeTags();
             foreach ($entityModel->tags as $tag) {
                 $this->entity->addTag($tag);
             }
             $this->em->persist($this->entity);
             $this->createHistory();
             $this->updateTags($this->entity->getTags());
             $this->em->flush();
             return true;
         }
         return false;
     }
     return false;
 }
Example #19
0
 /**
  * @param Form $form
  * @param Request $request
  * @param callable $preValidation callback to be called before the form is validated
  * @throws \Mcfedr\JsonFormBundle\Exception\InvalidFormHttpException
  * @throws \Mcfedr\JsonFormBundle\Exception\MissingFormHttpException
  * @throws \Mcfedr\JsonFormBundle\Exception\InvalidJsonHttpException
  */
 protected function handleJsonForm(Form $form, Request $request, callable $preValidation = null)
 {
     $bodyJson = $request->getContent();
     if (!($body = json_decode($bodyJson, true))) {
         throw new InvalidJsonHttpException();
     }
     if (!isset($body[$form->getName()])) {
         throw new MissingFormHttpException($form);
     }
     $form->submit($body[$form->getName()]);
     if ($preValidation) {
         $preValidation();
     }
     if (!$form->isValid()) {
         throw new InvalidFormHttpException($form);
     }
 }
Example #20
0
 /**
  * Bind search / filter data to the datalist
  *
  * @param mixed $data a data array, a Request instance or an arbitrary object
  * @return DatalistInterface
  */
 public function bind($data)
 {
     if ($data instanceof Request) {
         $data = $data->query->all();
     }
     // Handle pagination
     if (isset($data['page'])) {
         $this->setPage($data['page']);
     }
     // Handle search
     if (isset($data['search'])) {
         $this->searchQuery = $data['search'];
         $this->searchForm->submit(array('search' => $data['search']));
     }
     // Handle filters
     foreach ($this->filters as $filter) {
         if (isset($data[$filter->getName()]) && "" !== $data[$filter->getName()]) {
             $this->filterData[$filter->getName()] = $data[$filter->getName()];
         } elseif ($filter->hasOption('default')) {
             $this->filterData[$filter->getName()] = $filter->getOption('default');
         }
     }
     $this->filterForm->submit($this->filterData);
 }
Example #21
0
 /**
  * Handle the upload POST.
  *
  * @param Request $request   The Symfony Request
  * @param Form    $form
  * @param string  $namespace The filesystem namespace
  * @param string  $path      The path prefix
  */
 private function handleUpload(Request $request, Form $form, $namespace, $path)
 {
     $form->submit($request);
     if (!$form->isValid()) {
         $this->flashes()->error(Trans::__('general.phrase.file-upload-failed'));
         return;
     }
     $files = $request->files->get($form->getName());
     $files = $files['FileUpload'];
     foreach ($files as $fileToProcess) {
         $fileToProcess = ['name' => $fileToProcess->getClientOriginalName(), 'tmp_name' => $fileToProcess->getPathName()];
         $originalFilename = $fileToProcess['name'];
         $filename = preg_replace('/[^a-zA-Z0-9_\\.]/', '_', basename($originalFilename));
         if ($this->app['filepermissions']->allowedUpload($filename)) {
             $this->processUpload($namespace, $path, $filename, $fileToProcess);
         } else {
             $extensionList = [];
             foreach ($this->app['filepermissions']->getAllowedUploadExtensions() as $extension) {
                 $extensionList[] = '<code>.' . htmlspecialchars($extension, ENT_QUOTES) . '</code>';
             }
             $extensionList = implode(' ', $extensionList);
             $this->flashes()->error(Trans::__("File '%file%' could not be uploaded (wrong/disallowed file type). Make sure the file extension is one of the following:", ['%file%' => $filename]) . $extensionList);
         }
     }
 }
Example #22
0
 public function testValidateDataDoesNotWalkScalars()
 {
     $graphWalker = $this->createMockGraphWalker();
     $metadataFactory = $this->createMockMetadataFactory();
     $context = new ExecutionContext('Root', $graphWalker, $metadataFactory);
     $valueTransformer = $this->createMockTransformer();
     $form = new Form('author', array('value_transformer' => $valueTransformer));
     $graphWalker->expects($this->never())->method('walkReference');
     $valueTransformer->expects($this->atLeastOnce())->method('reverseTransform')->will($this->returnValue('foobar'));
     $form->submit(array('foo' => 'bar'));
     // reverse transformed to "foobar"
     $form->validateData($context);
 }
Example #23
0
 /**
  * @param Request $request
  * @param Form $form
  * @param string $id
  * @param HangmanBundle\Game\Application\Command $command
  * @return View|Form
  * @throws \Exception
  */
 private function handleForm(Request $request, Form $form, $id, $command)
 {
     $form->submit($request);
     if ($form->isValid()) {
         $this->handleCommand($command);
         return true;
     }
     return $form;
 }
Example #24
0
 /**
  * Handle a POST from user edit or first user creation.
  *
  * @param \Silex\Application          $app
  * @param Symfony\Component\Form\Form $form      A Symfony form
  * @param boolean                     $firstuser If this is a first user set up
  *
  * @return array|boolean An array of user elements, otherwise false
  */
 private function validateUserForm(Application $app, Form $form, $firstuser = false)
 {
     $form->submit($app['request']->get($form->getName()));
     if ($form->isValid()) {
         $user = $form->getData();
         if ($firstuser) {
             $user['roles'] = array(Permissions::ROLE_ROOT);
         } else {
             $id = isset($user['id']) ? $user['id'] : null;
             $user['roles'] = $app['users']->filterManipulatableRoles($id, $user['roles']);
         }
         $res = $app['users']->saveUser($user);
         if ($user['id']) {
             $app['logger.system']->info(Trans::__('page.edit-users.log.user-updated', array('%user%' => $user['displayname'])), array('event' => 'security'));
         } else {
             $app['logger.system']->info(Trans::__('page.edit-users.log.user-added', array('%user%' => $user['displayname'])), array('event' => 'security'));
             if ($firstuser) {
                 // Create a welcome email
                 $mailhtml = $app['render']->render('email/firstuser.twig', array('sitename' => $app['config']->get('general/sitename')))->getContent();
                 try {
                     // Send a welcome email
                     $message = $app['mailer']->createMessage('message')->setSubject(Trans::__('New Bolt site has been set up'))->setFrom(array($app['config']->get('general/mailoptions/senderMail', $user['email']) => $app['config']->get('general/mailoptions/senderName', $app['config']->get('general/sitename'))))->setTo(array($user['email'] => $user['displayname']))->setBody(strip_tags($mailhtml))->addPart($mailhtml, 'text/html');
                     $app['mailer']->send($message);
                 } catch (\Exception $e) {
                     // Sending message failed. What else can we do, sending with snailmail?
                     $app['logger.system']->error("The 'mailoptions' need to be set in app/config/config.yml", array('event' => 'config'));
                 }
             }
         }
         if ($res) {
             $app['session']->getFlashBag()->add('success', Trans::__('page.edit-users.message.user-saved', array('%user%' => $user['displayname'])));
         } else {
             $app['session']->getFlashBag()->add('error', Trans::__('page.edit-users.message.saving-user', array('%user%' => $user['displayname'])));
         }
         return $user;
     }
     return false;
 }
 public function submit($data)
 {
     $this->removedFields = array();
     if (null === $data) {
         $data = array();
     }
     foreach ($this as $name => $field) {
         if (!isset($data[$name]) && $this->getOption('modifiable') && '$$key$$' != $name) {
             $this->remove($name);
             $this->removedFields[] = $name;
         }
     }
     foreach ($data as $name => $value) {
         if (!isset($this[$name]) && $this->getOption('modifiable')) {
             $this->add($this->newField($name, $name));
         }
     }
     parent::submit($data);
 }
Example #26
0
 /**
  * @param Request $request
  * @param $form
  *
  * @return mixed
  */
 protected function handleRestForm(Request $request, Form $form)
 {
     return $form->submit(json_decode($request->getContent(), true));
 }
Example #27
0
 /**
  * Handle a POST from user edit or first user creation.
  *
  * @param Request $request
  * @param Form    $form      A Symfony form
  * @param boolean $firstuser If this is a first user set up
  *
  * @return Entity\Users|false
  */
 private function validateUserForm(Request $request, Form $form, $firstuser = false)
 {
     $form->submit($request->get($form->getName()));
     if (!$form->isValid()) {
         return false;
     }
     $userEntity = new Entity\Users($form->getData());
     $userEntity->setUsername($this->app['slugify']->slugify($userEntity->getUsername()));
     if (!$firstuser) {
         $userEntity->setRoles($this->users()->filterManipulatableRoles($userEntity->getId(), $userEntity->getRoles()));
     }
     if ($this->getRepository('Bolt\\Storage\\Entity\\Users')->save($userEntity)) {
         $this->flashes()->success(Trans::__('page.edit-users.message.user-saved', ['%user%' => $userEntity->getDisplayname()]));
         $this->notifyUserSave($request, $userEntity->getDisplayname(), $userEntity->getEmail(), $firstuser);
     } else {
         $this->flashes()->error(Trans::__('page.edit-users.message.saving-user', ['%user%' => $userEntity->getDisplayname()]));
     }
     return $userEntity;
 }
Example #28
0
 /**
  * @param Form $form
  * @return bool
  */
 public function processForm(Form $form)
 {
     $form->submit($this->getRequest());
     return $form->isValid();
 }
Example #29
0
 /**
  * {@inheritDoc}
  */
 public function submit($data)
 {
     if ($this->mode === self::FORM) {
         parent::submit($data);
     } else {
         Field::submit($data);
     }
 }
 public function testSubmitWithoutStringShouldThrowException()
 {
     $this->setExpectedExceptionRegExp('InvalidArgumentException', '/^Invalid argument: the submitted variable must be a string when you enable the json_format option.$/');
     $this->form->submit(['invalid json']);
 }