本文整理汇总了PHP中Symfony\Component\Form\Form::getErrors方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getErrors方法的具体用法?PHP Form::getErrors怎么用?PHP Form::getErrors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::getErrors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: convertFormToArray
private function convertFormToArray(GenericSerializationVisitor $visitor, Form $data)
{
$isRoot = null === $visitor->getRoot();
$form = new \ArrayObject();
$errors = [];
foreach ($data->getErrors() as $error) {
$errors[] = $this->getErrorMessage($error);
}
if (!empty($errors)) {
$form['errors'] = $errors;
}
$children = [];
foreach ($data->all() as $child) {
if ($child instanceof Form) {
$children[$child->getName()] = $this->convertFormToArray($visitor, $child);
}
}
if (!empty($children)) {
$form['children'] = $children;
}
if ($isRoot) {
$visitor->setRoot($form);
}
return $form;
}
示例2: getErrorMessages
protected function getErrorMessages(\Symfony\Component\Form\Form $form, $name)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
foreach ($form->all() as $child) {
$type = $child->getConfig()->getType()->getName();
if ($child->count() && $type !== 'choice') {
$childErrors = $this->getErrorMessages($child, $child->getName());
if (sizeof($childErrors)) {
$errors = array_merge($errors, $childErrors);
}
} else {
if (!$child->isValid()) {
if ($name == "responsable1" || $name == "responsable2") {
$errors[$child->getParent()->getParent()->getName() . '_' . $name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
} else {
$errors[$name . '_' . $child->getName()] = $this->getErrorMessages($child, $child->getName());
}
}
}
}
return $errors;
}
示例3: stringifyFormErrors
public function stringifyFormErrors(Form $form)
{
$errors = [];
foreach ($form->getErrors(true, true) as $error) {
$errors[] = $error->getMessage();
}
return implode('<br>', $errors);
}
示例4: createView
public function createView(Form $form, $template, $parameters, $extraParameters = [])
{
$html = $this->templating->render($template, $parameters);
$response = new JsonResponse();
$response->setData(array_merge($extraParameters, ['submitted' => $form->isSubmitted(), 'errors' => count($form->getErrors(true)), 'html' => $html]));
return $response;
}
示例5: getFormErrorMessages
/**
* Gets a form error messages
*
* @param Form $form
*
* @return array|string
*/
public static function getFormErrorMessages(Form $form)
{
$errors = [];
foreach ($form->getErrors(true, true) as $error) {
$errors = $error->getMessage();
}
return $errors;
}
示例6: getErrorMessages
private function getErrorMessages(Form $form)
{
$errors = [];
foreach ($form->getErrors(true, true) as $key => $error) {
$errors[] = $error->getMessage();
}
return $errors;
}
示例7: stringifyFormErrors
public function stringifyFormErrors(Form $form)
{
$errors = [];
foreach ($form->getErrors(TRUE, TRUE) as $error) {
$errors[] = $error->getMessage();
}
//return implode(', ', $errors);
return !empty($errors[0]) ? $errors[0] : NULL;
}
示例8: addFormErrors
/**
* Method to add form errors to the response array
*
* @param Form $form
* @return \AppBundle\Controller\AppController
*/
protected function addFormErrors(Form $form)
{
$response = array();
$response['errorCode'] = self::FORM_ERRORS;
foreach ($form->getErrors(true) as $error) {
$response['errorMessage'][] = $error->getMessage();
}
$this->response = $response;
return $this;
}
示例9: tryFormValidate
/**
* フォームのバリデーションを行う
* ※ServiceクラスでEntityのバリデーションを行っているが、
* FormTypeクラスで設定したチェックや、CSRFトークンのチェックは
* $form->isValid()でないと検証できないため、
* フォームの検証の場合、本メソッドを使用すること
*
* @param Form $form
* @throws FormValidationException
*/
private function tryFormValidate(Form $form)
{
if (!$form->isValid()) {
$exception = new FormValidationException();
foreach ($form->getErrors(true, true) as $error) {
$exception->addErrorMessage($error->getMessage());
}
throw $exception;
}
}
示例10: saveErrorsToFlashBag
/**
* @param Request $request
* @param
* $form
* @param
* $errors
*/
protected function saveErrorsToFlashBag(Request $request, Form $form)
{
$formClass = get_class($form->getConfig()->getType()->getInnerType());
$errors = [];
foreach ($form->getErrors(TRUE) as $error) {
$cause = $error->getCause();
$errors[] = ['message' => $error->getMessage(), 'messageTemplate' => $error->getMessageTemplate(), 'messageParameters' => $error->getMessageParameters(), 'messagePluralization' => $error->getMessagePluralization(), 'cause' => preg_replace('/data\\.|children\\[(.*?)\\]/', '$1', $cause->getPropertyPath()), 'invalidValue' => $cause->getInvalidValue()];
}
$this->addFlash('validation_error_' . $formClass, $errors);
$this->addFlash('validation_error_request_' . $formClass, $request);
}
示例11: getFormErrorsArray
public function getFormErrorsArray(Form $form, $prefix = '')
{
$errors = array();
$errors['count'] = count($form->getErrors());
$errors['count_deep'] = count($form->getErrors(true));
if (count($form->getErrors()) > 0) {
$errors['global'] = array();
}
/**
* @var FormError $globalError
*/
foreach ($form->getErrors() as $globalError) {
$errors['global'][] = $this->translator->trans($globalError->getMessage());
}
/**
* @var FormInterface $child
*/
foreach ($form->all() as $name => $child) {
if (count($child->getErrors()) > 0) {
$errors[sprintf('%s%s', $prefix, $name)] = array();
}
/**
* @var FormError $error
*/
foreach ($child->getErrors() as $error) {
$errors[sprintf('%s%s', $prefix, $name)][] = $this->translator->trans($error->getMessage());
}
if (count($child->all()) > 0) {
foreach ($child->all() as $nameChild => $childChild) {
$name = sprintf('%s_%s', $name, $nameChild);
if (count($childChild->getErrors()) > 0) {
$errors[sprintf('%s%s', $prefix, $name)] = array();
}
foreach ($childChild->getErrors() as $error) {
$errors[sprintf('%s%s', $prefix, $name)][] = $this->translator->trans($error->getMessage());
}
}
}
}
return $errors;
}
示例12: getErrors
/**
* @return array
*/
protected function getErrors()
{
$errors = [];
$generalErrors = [];
foreach ($this->form->getErrors() as $error) {
$generalErrors[] = $error->getMessage();
}
if (!empty($generalErrors)) {
$errors['general'] = $generalErrors;
}
foreach ($this->form->all() as $field) {
$fieldErrors = [];
foreach ($field->getErrors() as $error) {
$fieldErrors[] = $error->getMessage();
}
if (!empty($fieldErrors)) {
$errors[$field->getName()] = $fieldErrors;
}
}
return $errors;
}
示例13: 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;
}
示例14: getErrorMessages
/**
* @param Form $form
*
* @return array
*/
public function getErrorMessages(Form $form)
{
$errors = array();
foreach ($form->getErrors() as $key => $error) {
$errors[] = $error->getMessage();
}
foreach ($form->all() as $child) {
if (!$child->isValid()) {
$errors[$child->getName()] = $this->getErrorMessages($child);
}
}
return $errors;
}
示例15: serializeFormErrors
public function serializeFormErrors(\Symfony\Component\Form\Form $form, $flat_array = false, $add_form_name = false, $glue_keys = '_')
{
$errors = array();
$errors['global'] = array();
$errors['fields'] = array();
foreach ($form->getErrors() as $error) {
$errors['global'][] = $error->getMessage();
}
$errors['fields'] = $this->serialize($form);
if ($flat_array) {
$errors['fields'] = $this->arrayFlatten($errors['fields'], $glue_keys, $add_form_name ? $form->getName() : '');
}
return $errors;
}