當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Form::getName方法代碼示例

本文整理匯總了PHP中Symfony\Component\Form\Form::getName方法的典型用法代碼示例。如果您正苦於以下問題:PHP Form::getName方法的具體用法?PHP Form::getName怎麽用?PHP Form::getName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Form\Form的用法示例。


在下文中一共展示了Form::getName方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: isValid

 public function isValid(\Symfony\Component\Form\Form &$form)
 {
     $viewData = $form->getViewData();
     //pour le champ hidden allFieldsAreThere de Revision
     if (!is_object($viewData) && 'allFieldsAreThere' == $form->getName()) {
         return true;
     }
     if ($viewData instanceof Revision) {
         /** @var DataField $dataField */
         $dataField = $viewData->getDatafield();
     } elseif ($viewData instanceof DataField) {
         /** @var DataField $dataField */
         $dataField = $viewData;
     } else {
         throw new \Exception("Unforeseen type of viewData");
     }
     if ($dataField->getFieldType() !== null && $dataField->getFieldType()->getType() !== null) {
         $dataFieldTypeClassName = $dataField->getFieldType()->getType();
         /** @var DataFieldType $dataFieldType */
         $dataFieldType = new $dataFieldTypeClassName();
     }
     $isValid = true;
     if (isset($dataFieldType) && $dataFieldType->isContainer()) {
         //If datafield is container or type is null => Container => Recursive
         $formChildren = $form->all();
         foreach ($formChildren as $child) {
             if ($child instanceof \Symfony\Component\Form\Form) {
                 $tempIsValid = $this->isValid($child);
                 //Recursive
                 $isValid = $isValid && $tempIsValid;
             }
         }
         if (!$isValid) {
             $form->addError(new FormError("At least one child is not valid!"));
         }
     }
     //   		$isValid = $isValid && $dataFieldType->isValid($dataField);
     if (isset($dataFieldType) && !$dataFieldType->isValid($dataField)) {
         $isValid = false;
         $form->addError(new FormError("This Field is not valid! " . $dataField->getMessages()[0]));
     }
     return $isValid;
 }
開發者ID:theus77,項目名稱:ElasticMS,代碼行數:43,代碼來源:DataService.php

示例2: validateForm

 /**
  * Validate the given request with the given rules.
  *
  * @param  \Symfony\Component\Form\Form  $form
  * @param  \Illuminate\Http\Request  $request
  * @param  array  $rules
  * @param  array  $messages
  * @return void
  */
 public function validateForm(Form $form, Request $request, array $rules, array $messages = array())
 {
     $data = $form->getName() ? $request->get($form->getName()) : $request->all();
     $validator = $this->getValidationFactory()->make($data, $rules, $messages);
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
 }
開發者ID:seydu,項目名稱:laravel-form-bridge,代碼行數:17,代碼來源:ValidatesForms.php

示例3: getErrorsArray

 /**
  * @param Form $form The form
  * @param string $namePrefix The field name prefix (concatenation of parents names).
  * @return array The form errors, as an array
  */
 private function getErrorsArray(Form $form, $namePrefix = '')
 {
     $formName = $namePrefix ? sprintf('%s[%s]', $namePrefix, $form->getName()) : $form->getName();
     $errors = array();
     foreach ($form->getErrors() as $error) {
         if (!isset($errors[$formName])) {
             $errors[$formName] = array();
         }
         $errors[$formName][] = $error->getMessage();
     }
     return $errors;
 }
開發者ID:blab2015,項目名稱:seh,代碼行數:17,代碼來源:AbstractFormErrorsHelper.php

示例4: serializeFormToXml

 public function serializeFormToXml(XmlSerializationVisitor $visitor, Form $form, array $type)
 {
     if (null === $visitor->document) {
         $visitor->document = $visitor->createDocument(null, null, false);
         $visitor->document->appendChild($formNode = $visitor->document->createElement('form'));
         $visitor->setCurrentNode($formNode);
     } else {
         $visitor->getCurrentNode()->appendChild($formNode = $visitor->document->createElement('form'));
     }
     $formNode->setAttribute('name', $form->getName());
     $formNode->appendChild($errorsNode = $visitor->document->createElement('errors'));
     foreach ($form->getErrors() as $error) {
         $errorNode = $visitor->document->createElement('entry');
         $errorNode->appendChild($this->serializeFormErrorToXml($visitor, $error, array()));
         $errorsNode->appendChild($errorNode);
     }
     foreach ($form->all() as $child) {
         if ($child instanceof Form) {
             if (null !== ($node = $this->serializeFormToXml($visitor, $child, array()))) {
                 $formNode->appendChild($node);
             }
         }
     }
     return $formNode;
 }
開發者ID:baardbaard,項目名稱:bb-twitterfeed,代碼行數:25,代碼來源:FormErrorHandler.php

示例5: function

 /**
  * @param Form   $form
  * @param string $path
  *
  * @return Form
  */
 public static function &getForm(Form &$form, $path)
 {
     $keys = array_filter(preg_split('#[\\.\\[\\]]+#', $path), function ($val) {
         return $val;
     });
     $prefix = substr($path, 0, strlen($form->getName()) + 1);
     if ($form->getName() . '[' === $prefix || $form->getName() . '.' === $prefix) {
         array_shift($keys);
     }
     $val = $form;
     foreach ($keys as $k) {
         $val = static::_get($val, $k);
     }
     /* @var $val Form */
     return $val;
 }
開發者ID:stopsopa,項目名稱:utils,代碼行數:22,代碼來源:UtilFormAccessor.php

示例6: handleJsonForm

 /**
  * @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);
     }
 }
開發者ID:tamcy,項目名稱:json-form,代碼行數:25,代碼來源:JsonController.php

示例7: resolveInput

 /**
  * Resolve input and get files from request
  * @return array
  */
 private function resolveInput()
 {
     if ($this->secure_upload === false) {
         return $this->rq->files->all();
     }
     $parts = $this->rq->files->get($this->form->getName());
     return $parts[$this->input_name];
 }
開發者ID:fire1,項目名稱:liby,代碼行數:12,代碼來源:Image.php

示例8: handle

 /**
  * @param Form    $form
  * @param Request $request
  * @param array   $options
  *
  * @return bool
  */
 public function handle(Form $form, Request $request, array $options = null)
 {
     if (!$request->isMethod('POST')) {
         return false;
     }
     $form->bind($request->request->get($form->getName()));
     if (!$form->isBound() || !$form->isValid()) {
         return false;
     }
     $this->usermanager->createUser($form->getData()->getUser());
     return true;
 }
開發者ID:nicolas-grekas,項目名稱:workshop-symfony3,代碼行數:19,代碼來源:RegistrationFormHandler.php

示例9: getErrorMessages

 protected function getErrorMessages(Form $form)
 {
     $errors = array();
     foreach ($form->getErrors() as $key => $error) {
         $errors[$key] = $error->getMessage();
     }
     foreach ($form->all() as $child) {
         if (!$child->isValid()) {
             $key = sprintf('%s[%s]', $form->getName(), $child->getName());
             $errors[$key] = $this->getErrorMessages($child);
         }
     }
     return $errors;
 }
開發者ID:tarnawski,項目名稱:JSONMock-backend,代碼行數:14,代碼來源:ApiController.php

示例10: upload

 /**
  * @param Request $request
  * @param Form $articleForm
  * @return mixed
  * @throws \Exception
  */
 protected function upload(Request $request, Form $form, $width, $height)
 {
     $files = $request->files->get($form->getName());
     if (!empty($files['image'])) {
         $path = __DIR__ . self::UPLOAD_DIR;
         $filename = $files['image']->getClientOriginalName();
         $filepath = $path . $filename;
         $files['image']->move($path, $filename);
         chmod($filepath, 0755);
         //ToDo: renommer les images en ajoutant uniqid()
         Image::open($filepath)->zoomCrop($width, $height, "#346A85", "center", "center")->save($filepath);
         return $filename;
     } else {
         return false;
     }
 }
開發者ID:nicolastorre,項目名稱:portfolio,代碼行數:22,代碼來源:DefaultController.php

示例11: getFormErrors

 /**
  * @param Form $form
  * @return array
  */
 protected function getFormErrors(Form $form)
 {
     $errors = array();
     // Global
     foreach ($form->getErrors() as $error) {
         $errors[$form->getName()][] = $error->getMessage();
     }
     // Fields
     foreach ($form as $child) {
         if (!$child->isValid()) {
             foreach ($child->getErrors() as $error) {
                 $errors[$child->getName()][] = $error->getMessage();
             }
         }
     }
     return $errors;
 }
開發者ID:Asisyas,項目名稱:EqPay,代碼行數:21,代碼來源:OrderController.php

示例12: getAllErrors

 public static function getAllErrors(Form $form, $parent_prefix = '')
 {
     $id = $parent_prefix . ($parent_prefix ? '_' : '') . $form->getName();
     $errors = array($id . '_errors' => array());
     foreach ($form->getErrors() as $error) {
         $errors[$id . '_errors'][] = array('error' => self::formatErrors($error));
     }
     if (!count($errors[$id . '_errors'])) {
         unset($errors[$id . '_errors']);
     }
     foreach ($form->getChildren() as $child) {
         if ($_errors = self::getAllErrors($child, $id)) {
             $errors = array_merge($errors, $_errors);
         }
     }
     if (count($errors)) {
         return $errors;
     } else {
         return false;
     }
 }
開發者ID:renegare,項目名稱:Renegare-Bundles,代碼行數:21,代碼來源:FormTools.php

示例13: sanitizeCollections

 /**
  * Removes submitted errant form fields
  * @param Symfony\Component\Form\Form $form
  * @param Symfony\Component\HttpFoundation\Request $request
  * @param Array $collections
  */
 public function sanitizeCollections(Form &$form, Request &$request, Array $collections) {
     $formName = $form->getName();
     $submission = $request->request->get($formName);
     foreach ($collections as $collection => $fields) {
         $total = count($submission[$collection])+1;
         for ($i = 0; $i < $total; $i++) {
             foreach ($fields as $field) {
                 if (empty($submission[$collection][$i][$field])) {
                     unset($submission[$collection][$i]);
                     break;
                 }
             }
         }
     }
     $request->request->set($formName, $submission);
 }
開發者ID:ninethousand,項目名稱:NineThousandJobqueueBundle,代碼行數:22,代碼來源:ScheduledJobController.php

示例14: validateUserForm

 /**
  * 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;
 }
開發者ID:atiarda,項目名稱:bolt,代碼行數:28,代碼來源:Users.php

示例15: validateUserForm

 /**
  * 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;
 }
開發者ID:realitygaps,項目名稱:site-v20,代碼行數:47,代碼來源:Backend.php


注:本文中的Symfony\Component\Form\Form::getName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。