getErrors() public method

Returns global validation errors.
public getErrors ( ) : array
return array
示例#1
0
 /**
  * @return array
  */
 public function findErrors()
 {
     $formErrors = method_exists($this->form, 'getAllErrors') ? $this->form->getErrors() : $this->form->getErrors();
     if (!$formErrors) {
         return array();
     }
     $form = $this->form;
     $translate = function ($errors) use($form) {
         if ($translator = $form->getTranslator()) {
             // If we have translator, translate!
             foreach ($errors as $key => $val) {
                 $errors[$key] = $translator->translate($val);
             }
         }
         return $errors;
     };
     if (!$this->errorsAtInputs) {
         return $translate($formErrors);
     }
     if (method_exists($this->form, 'getAllErrors')) {
         return $translate($this->form->getErrors());
     }
     foreach ($this->form->getControls() as $control) {
         /** @var \Nette\Forms\Controls\BaseControl $control */
         if (!$control->hasErrors()) {
             continue;
         }
         $formErrors = array_diff($formErrors, $control->getErrors());
     }
     return $translate($formErrors);
 }
 /**
  * @param bool $ownOnly - true = render only global errors, false = render all errors of all controls
  * @return Html
  */
 public function renderGlobalErrors($ownOnly = TRUE)
 {
     $errors = $ownOnly ? $this->form->getOwnErrors() : $this->form->getErrors();
     $container = clone $this->prototypes->getGlobalErrors();
     foreach ($errors as $error) {
         $alert = clone $this->prototypes->getGlobalError();
         $this->addContent($alert->getPlaceholder(), $error);
         $container->getPlaceholder()->addHtml($alert);
     }
     return $container;
 }
示例#3
0
 /**
  * Renders validation errors (per form or per control).
  * @return string
  */
 public function renderErrors(Nette\Forms\IControl $control = NULL)
 {
     $errors = $control === NULL ? $this->form->getErrors() : $control->getErrors();
     if (count($errors)) {
         $ul = $this->getWrapper('error container');
         $li = $this->getWrapper('error item');
         foreach ($errors as $error) {
             $item = clone $li;
             if ($error instanceof Html) {
                 $item->add($error);
             } else {
                 $item->setText($error);
             }
             $ul->add($item);
         }
         return "\n" . $ul->render(0);
     }
 }
 /**
  * @return array
  */
 public function findErrors()
 {
     $formErrors = $this->errorsAtInputs ? $this->form->getOwnErrors() : $this->form->getErrors();
     if (!$formErrors) {
         return array();
     }
     $form = $this->form;
     $translate = function ($errors) use($form) {
         if ($translator = $form->getTranslator()) {
             // If we have translator, translate!
             foreach ($errors as $key => $val) {
                 $errors[$key] = $translator->translate($val);
             }
         }
         return $errors;
     };
     return $translate($formErrors);
 }
 /**
  * Renders validation errors (per form or per control).
  * @return string
  */
 public function renderErrors(Nette\Forms\IControl $control = NULL, $own = TRUE)
 {
     $errors = $control ? $control->getErrors() : ($own ? $this->form->getOwnErrors() : $this->form->getErrors());
     if (!$errors) {
         return;
     }
     $container = $this->getWrapper($control ? 'control errorcontainer' : 'error container');
     $item = $this->getWrapper($control ? 'control erroritem' : 'error item');
     foreach ($errors as $error) {
         $item = clone $item;
         if ($error instanceof Html) {
             $item->add($error);
         } else {
             $item->setText($error);
         }
         $container->add($item);
     }
     return "\n" . $container->render($control ? 1 : 0);
 }
 /**
  * @return array
  */
 public function findErrors()
 {
     if (!($formErrors = $this->form->getErrors())) {
         return array();
     }
     if (!$this->errorsAtInputs) {
         return $formErrors;
     }
     foreach ($this->form->getControls() as $control) {
         /** @var \Nette\Forms\Controls\BaseControl $control */
         if (!$control->hasErrors()) {
             continue;
         }
         $formErrors = array_diff($formErrors, $control->getErrors());
     }
     // If we have translator, translate!
     if ($translator = $this->form->getTranslator()) {
         foreach ($formErrors as $key => $val) {
             $formErrors[$key] = $translator->translate($val);
         }
     }
     return $formErrors;
 }
示例#7
0
 /**
  * Render the templates
  *
  * @param \Nette\Forms\Form $form
  * @return void
  */
 public function render(\Nette\Forms\Form $form)
 {
     if ($form === $this->form) {
         // don't forget for second run, @hosiplan! ;)
         foreach ($this->form->getControls() as $control) {
             $control->setOption('rendered', FALSE);
         }
         echo $this->template;
         return;
     }
     // Store the current form instance
     $this->form = $form;
     // Translator available?
     if ($translator = $form->getTranslator()) {
         // intentional =
         $this->template->setTranslator($translator);
     }
     // Pre-proccess form
     $errors = $form->getErrors();
     foreach ($form->getControls() as $control) {
         $control->setOption('rendered', FALSE);
         if (!$control->getOption('blockname', FALSE)) {
             $ex = explode('\\', get_class($control));
             $control->setOption('blockname', end($ex));
         }
         if ($this->errorsAtInputs) {
             $errors = array_diff($errors, $control->errors);
         }
     }
     // Assign to template
     $this->template->form = $form;
     $this->template->errors = $errors;
     $this->template->renderer = $this;
     $this->template->errorsAtInputs = $this->errorsAtInputs;
     // And echo the output
     echo $this->template;
 }
      });
    });
    //]]> -->
  </script>
</head>
<body>
  <h1>RadekDostal\NetteComponents\DateTimePicker\TbDateTimePicker example</h1>
  <?php 
$form->render('begin');
?>
  <?php 
if ($form->hasErrors() === TRUE) {
    ?>
  <ul class="error">
    <?php 
    foreach ($form->getErrors() as $error) {
        ?>
    <li><?php 
        echo htmlspecialchars($error);
        ?>
</li>
    <?php 
    }
    ?>
  </ul>
  <?php 
}
?>
  <div class="form-group">
    <?php 
echo $form['date']->getLabel();
示例#9
0
		text-align: right;
	}
	</style>

	<script src="netteForms.js"></script>
</head>

<body>
	<h1>Nette\Forms manual form rendering</h1>

	<?php 
$form->render('begin');
?>

	<?php 
if ($form->getErrors()) {
    ?>
	<p>Opravte chyby:</p>
	<?php 
    $form->render('errors');
    ?>
	<?php 
}
?>

	<fieldset>
		<legend>Personal data</legend>
		<table>
		<tr class="required">
			<th><?php 
echo $form['name']->getLabel('Your name:');
示例#10
0
 /**
  * Do the magic
  */
 public function processActions()
 {
     // WP_List_Table export
     \SimpleSubscribe\TableSubscribes::process();
     // settings form
     if ($this->formSettings->isSubmitted() && $this->formSettings->isValid()) {
         $values = $this->formSettings->getValues(TRUE);
         // if there are cateogires selected, and ALL as well, uncheck remaining
         if (count(array_filter($values['cat'])) > 0 && $values['cat']['0'] == TRUE) {
             foreach ($values['cat'] as $key => $value) {
                 $values['cat'][$key] = FALSE;
                 $this->formSettings['cat'][$key]->value = FALSE;
             }
             $values['cat']['0'] = TRUE;
             $this->formSettings['cat']['0']->value = TRUE;
             // if there is other category selected, unselect ALL
         } elseif (count(array_filter($values['cat'])) > 1) {
             $values['cat']['0'] = FALSE;
             $this->formSettings['cat']['0']->value = FALSE;
             // if there's no category selected, select ALL
         } elseif (!in_array(TRUE, $values['cat'])) {
             $values['cat']['0'] = TRUE;
             $this->formSettings['cat']['0']->value = TRUE;
         }
         $this->settings->saveSettings($values);
         $this->addNotice('updated', 'Settings successfully saved.');
     } elseif ($this->formSettings->hasErrors()) {
         foreach ($this->formSettings->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // email template (saved in settings table tho)
     if ($this->formEmailTemplate->isSubmitted() && $this->formEmailTemplate->isValid()) {
         $this->settings->saveSettings($this->formEmailTemplate->getValues(TRUE));
         $this->addNotice('updated', 'Settings successfully saved.');
     } elseif ($this->formEmailTemplate->hasErrors()) {
         foreach ($this->formEmailTemplate->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // mass email
     if ($this->formEmail->isSubmitted() && $this->formEmail->isValid()) {
         try {
             $this->email->sendMassEmail($this->formEmail->getValues(TRUE));
             $this->addNotice('updated', 'Email successfully sent.');
         } catch (EmailException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formEmail->hasErrors()) {
         foreach ($this->formEmail->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // subscriber form
     if ($this->formSubscriber->isSubmitted() && $this->formSubscriber->isValid()) {
         try {
             $this->subscribers->addThruAdmin($this->formSubscriber->getValues());
             $this->addNotice('updated', 'Subscriber successfully added.');
         } catch (RepositarySubscribersException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formSubscriber->hasErrors()) {
         foreach ($this->formSubscriber->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // wp subscriber form
     if ($this->formSubscriberWp->isSubmitted() && $this->formSubscriberWp->isValid()) {
         try {
             $users = $this->formSubscriberWp->getValues(TRUE);
             $this->subscribers->addWpRegistered($users['users']);
             $this->addNotice('updated', 'Subscriber(s) successfully added.');
         } catch (RepositarySubscribersException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formSubscriberWp->hasErrors()) {
         foreach ($this->formSubscriberWp->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
     // email preview form
     if ($this->formEmailPreview->isSubmitted() && $this->formEmailPreview->isValid()) {
         try {
             $this->email->sendEmailPreview($this->formEmailPreview->getValues(TRUE));
             $this->addNotice('updated', 'Email Preview successfully sent.');
         } catch (EmailException $e) {
             $this->addNotice('error', $e->getMessage());
         }
     } elseif ($this->formEmailPreview->hasErrors()) {
         foreach ($this->formEmailPreview->getErrors() as $error) {
             $this->addNotice('error', $error);
         }
     }
 }