本文整理汇总了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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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];
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}