当前位置: 首页>>代码示例>>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;未经允许,请勿转载。