本文整理匯總了PHP中Symfony\Component\Form\FormInterface::handleRequest方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormInterface::handleRequest方法的具體用法?PHP FormInterface::handleRequest怎麽用?PHP FormInterface::handleRequest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::handleRequest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: process
/**
* Prepare & process form
*
* @author Jeremie Samson <jeremie@ylly.fr>
*
* @return bool
*/
public function process()
{
if ($this->request->isMethod('POST')) {
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
/** @var ModelUser $user */
$user = $this->form->getData();
if (!$user->getFirstname() || !$user->getLastname() || !$user->getEmailGalaxy() || !$user->getSection()) {
$this->form->addError(new FormError('Missing parameter(s)'));
} else {
if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL) || !filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
$error = new FormError('email invalid');
if (!filter_var($user->getEmail(), FILTER_VALIDATE_EMAIL)) {
$this->form->get('email')->addError($error);
}
if (!filter_var($user->getEmailGalaxy(), FILTER_VALIDATE_EMAIL)) {
$this->form->get('emailGalaxy')->addError($error);
}
} else {
$section_id = $this->em->getRepository('FaucondorBundle:Section')->find($user->getSection());
$section_code = $this->em->getRepository('FaucondorBundle:Section')->findOneBy(array("code" => $user->getSection()));
if (!$section_id && !$section_code) {
$this->form->get('section')->addError(new FormError('Section with id ' . $user->getSection() . ' not found'));
} else {
/** @var Section $section */
$section = $section_id ? $section_id : $section_code;
$this->onSuccess($user, $section);
return true;
}
}
}
}
}
return false;
}
示例2: process
/**
* Prepare & process form
*
* @author Jeremie Samson <jeremie@ylly.fr>
*
* @return bool
*/
public function process()
{
if ($this->request->isMethod('POST')) {
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
/** @var ModelUserRole $model */
$model = $this->form->getData();
if (!$model->getUser() || !$model->getRole()) {
$this->form->addError(new FormError('Missing parameter(s)'));
}
/** @var User $user */
$user = $this->em->getRepository('UserBundle:User')->find($model->getUser());
/** @var Post $role */
$role = $this->em->getRepository('FaucondorBundle:Post')->find($model->getRole());
if (!$user) {
$this->form->get('user')->addError(new FormError('User with id ' . $model->getUser() . ' not found '));
}
if (!$role) {
$this->form->get('role')->addError(new FormError('Role with id ' . $model->getRole() . ' not found '));
}
$this->onSuccess($user, $role);
return true;
}
}
return false;
}
示例3: process
/**
* Process job configuration form.
*
* @param JobConfigurationInterface $configuration
* @param Request $request
*
* @return bool
*/
public function process(JobConfigurationInterface $configuration, Request $request)
{
$this->form->setData($configuration);
$this->form->handleRequest($request);
if ($this->form->isValid()) {
$this->manager->add($configuration);
return true;
}
return false;
}
示例4: process
/**
* @param Order $entity
*
* @return bool True when successful processed, false otherwise
*/
public function process(Order $entity)
{
$this->form->setData($entity);
if ($this->form->handleRequest($this->requestStack->getCurrentRequest())->isValid()) {
$em = $this->registry->getManagerForClass(Order::class);
$em->persist($entity);
$em->flush($entity);
return true;
}
return false;
}
示例5: uploadComposerAction
/**
* @param Request $request
* @return JsonResponse
*/
public function uploadComposerAction(Request $request)
{
$this->composerForm->handleRequest($request);
if ($this->composerForm->isValid()) {
$data = $this->composerForm->getData();
$this->sonataNotificationsBackend->createAndPublish('upload.composer', array('body' => $data['body'], 'channelName' => $request->getSession()->get('channelName'), 'hasDevDependencies' => $data['hasDevDependencies']));
return new JsonResponse(array('status' => 'ok'));
}
$errors = array_map(function (FormError $error) {
return $error->getMessage();
}, $this->composerForm->get('body')->getErrors());
return new JsonResponse(array('status' => 'ko', 'message' => $errors));
}
示例6: process
/**
* {@inheritdoc}
*/
public function process($object = null)
{
$this->setObject($object);
if ($this->validateRequest()) {
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
return $this->onSuccess();
}
} elseif (!is_null($this->getObject())) {
$this->getForm()->setData($this->getObject());
}
return false;
}
示例7: changePasswordAction
public function changePasswordAction(Request $request)
{
$this->changePasswordForm->handleRequest($request);
if ($this->changePasswordForm->isValid()) {
$user = $this->tokenStorage->getToken()->getUser();
$formData = $this->changePasswordForm->getData();
$this->eventDispatcher->dispatch(AdminSecurityEvents::CHANGE_PASSWORD, new ChangePasswordEvent($user, $formData['plainPassword']));
$request->getSession()->invalidate();
$this->tokenStorage->setToken(null);
$request->getSession()->getFlashBag()->set('success', 'admin.change_password_message.success');
return new RedirectResponse($this->router->generate('fsi_admin_security_user_login'));
}
return $this->templating->renderResponse($this->changePasswordActionTemplate, array('form' => $this->changePasswordForm->createView()));
}
示例8: process
public function process()
{
$request = $this->getCurrentRequest();
if (null !== $request) {
$this->form->setData(new Authorize($request->request->has('accepted'), $request->query->all()));
if ('POST' === $request->getMethod()) {
$this->form->handleRequest($request);
if ($this->form->isValid()) {
$this->onSuccess();
return true;
}
}
}
return false;
}
示例9: process
/**
* @inheritDoc
*/
public function process(Request $request)
{
// Checking if a form has been set
if ($this->form == null) {
return false;
}
// Processing the handling of the form
$this->form->handleRequest($request);
// Shortcuts of the callbacks
$onBefore = $this->onBeforeCallback;
$onSuccess = $this->onSuccessCallback;
$onFailure = $this->onFailureCallback;
$onAfter = $this->onAfterCallback;
if ($onBefore != null) {
$onBefore($this->form);
}
$processed = false;
if ($this->form->isValid()) {
if ($onSuccess != null) {
$onSuccess($this->form);
}
$processed = true;
} else {
if ($onFailure != null) {
$onFailure($this->form);
}
}
if ($onAfter != null) {
$onAfter($this->form);
}
return $processed;
}
示例10: process
/**
* {@inheritdoc}
*/
public function process(FormInterface $form, Request $request)
{
$valid = false;
if ($request->isMethod('POST')) {
$form->handleRequest($request);
if ($form->isValid()) {
$transUnit = $form->getData();
$translations = $transUnit->filterNotBlankTranslations();
// only keep translations with a content
// link new translations to a file to be able to export them.
foreach ($translations as $translation) {
if (!$translation->getFile()) {
$file = $this->fileManager->getFor(sprintf('%s.%s.yml', $transUnit->getDomain(), $translation->getLocale()), $this->rootDir . '/Resources/translations');
if ($file instanceof FileInterface) {
$translation->setFile($file);
}
}
}
if ($transUnit instanceof PropelTransUnit) {
// The setTranslations() method only accepts PropelCollections
$translations = new \PropelObjectCollection($translations);
}
$transUnit->setTranslations($translations);
$this->storage->persist($transUnit);
$this->storage->flush();
$valid = true;
}
}
return $valid;
}
示例11: handle
public function handle(FormInterface $form, Request $request)
{
$form->handleRequest($request);
if (!$form->isValid()) {
return false;
}
$data = $form->getData();
if ($form->isSubmitted()) {
$user = $this->userManager->findUserByEmail($data['email']);
if (is_null($user)) {
$form->addError(new FormError($this->translator->trans('security.resetting.request.errors.email_not_found')));
return false;
}
if ($user->isPasswordRequestNonExpired($this->tokenTll)) {
$form->addError(new FormError($this->translator->trans('security.resetting.request.errors.password_already_requested')));
return false;
}
if ($user->getConfirmationToken() === null) {
$user->setConfirmationToken($this->tokenGenerator->generateToken());
}
$user->setPasswordRequestedAt(new \DateTime());
$this->userManager->resettingRequest($user);
}
return true;
}
示例12: handle
/**
* @param FormInterface $form
* @param Request $request
* @return bool
*/
private function handle(FormInterface $form, Request $request)
{
$form->handleRequest($request);
if ($form->isValid()) {
return true;
}
return false;
}
示例13: handleEdit
/**
* @param Badge $badge
*
* @return bool True on successfull processing, false otherwise
*/
public function handleEdit(Badge $badge, $badgeManager = null, $unawardBadge = false)
{
$this->form->setData($badge);
/** @var BadgeRule[]|\Doctrine\Common\Collections\ArrayCollection $originalRules */
$originalRules = $badge->getRules();
if ($this->request->isMethod('POST')) {
$this->form->handleRequest($this->request);
if ($this->form->isValid()) {
$this->handleUpload($this->form->get('file')->getData(), $badge);
$badgeRules = $badge->getRules();
$userBadges = $badge->getUserBadges();
if (0 < count($userBadges) && $this->badgeManager->isRuleChanged($badgeRules, $originalRules)) {
/** @var \Doctrine\ORM\UnitOfWork $unitOfWork */
$unitOfWork = $this->entityManager->getUnitOfWork();
$newBadge = clone $badge;
$newBadge->setVersion($badge->getVersion() + 1);
$unitOfWork->refresh($badge);
$badge->setDeletedAt(new \DateTime());
$this->entityManager->persist($newBadge);
// If the new badge has to be revoked from users already awarded, skip the next part
if (!$unawardBadge) {
foreach ($userBadges as $userBadge) {
// Award new version to previous users
$badgeManager->addBadgeToUser($newBadge, $userBadge->getUser());
}
}
} else {
// Compute which rules was deleted
foreach ($badgeRules as $rule) {
if ($originalRules->contains($rule)) {
$originalRules->removeElement($rule);
}
}
// Delete rules
foreach ($originalRules as $rule) {
$this->entityManager->remove($rule);
}
}
$this->entityManager->persist($badge);
$this->entityManager->flush();
return true;
}
}
return false;
}
示例14: valid
/**
* @param Request $request
* @param $form
* @return FormView, bool
*/
public function valid(Request $request, FormInterface $form)
{
$isValid = false;
if ($request->getMethod() == 'POST') {
$form->handleRequest($request);
$isValid = $form->isValid();
}
return [$form->createView(), $isValid];
}
示例15: handle
/**
* @param FormInterface $form
* @param Request $request
* @param array $options
*
* @return bool
*/
public function handle(FormInterface $form, Request $request, array $options = null)
{
$form->handleRequest($request);
if (!$form->isValid()) {
return false;
}
$this->handler->updateCredentials($form->getData()->getUser(), $form->getData()->getNewPassword());
return true;
}