/**
  * Validates a field.
  *
  * @param \FormFieldModel $formField
  * @param int             $step
  *
  * @return bool
  */
 public function validateField(\FormFieldModel $formField, $step)
 {
     $class = $GLOBALS['TL_FFL'][$formField->type];
     if (!class_exists($class)) {
         return true;
     }
     /** @var \Widget $widget */
     $widget = new $class($formField->row());
     $widget->required = $formField->mandatory ? true : false;
     // Needed for the hook
     $form = $this->createDummyForm();
     // HOOK: load form field callback
     if (isset($GLOBALS['TL_HOOKS']['loadFormField']) && is_array($GLOBALS['TL_HOOKS']['loadFormField'])) {
         foreach ($GLOBALS['TL_HOOKS']['loadFormField'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $widget = $objCallback->{$callback[1]}($widget, $this->getFormId(), $this->formModel->row(), $form);
         }
     }
     // Validation (needs to set POST values because the widget class searches
     // only in POST values :-(
     // This should only happen if value is not currently submitted and if
     // the value is neither submitted in POST nor in the session, we have
     // to default it to an empty string so the widget validates for mandatory
     // fields
     $fakeValidation = false;
     if (!isset($_POST[$widget->name])) {
         if ($this->isStoredInData($widget->name, $step)) {
             $value = $this->fetchFromData($widget->name, $step);
         } else {
             $value = '';
         }
         \Input::setPost($formField->name, $value);
         $fakeValidation = true;
     }
     $widget->validate();
     // Reset fake validation
     if ($fakeValidation) {
         \Input::setPost($formField->name, null);
     }
     // Special hack for upload fields because they delete $_FILES and thus
     // multiple validation calls will fail - sigh
     if ($widget instanceof \uploadable && isset($_SESSION['FILES'][$widget->name])) {
         $_FILES[$widget->name] = $_SESSION['FILES'][$widget->name];
     }
     // HOOK: validate form field callback
     if (isset($GLOBALS['TL_HOOKS']['validateFormField']) && is_array($GLOBALS['TL_HOOKS']['validateFormField'])) {
         foreach ($GLOBALS['TL_HOOKS']['validateFormField'] as $callback) {
             $objCallback = \System::importStatic($callback[0]);
             $widget = $objCallback->{$callback[1]}($widget, $this->getFormId(), $this->formModel->row(), $form);
         }
     }
     return !$widget->hasErrors();
 }
 /**
  * Send lead data using given notification
  *
  * @param int                                    $leadId
  * @param FormModel                              $form
  * @param \NotificationCenter\Model\Notification $notification
  *
  * @return bool
  */
 public static function send($leadId, \FormModel $form, \NotificationCenter\Model\Notification $notification)
 {
     $data = array();
     $labels = array();
     $leadDataCollection = \Database::getInstance()->prepare("\n            SELECT\n                name,\n                value,\n                (SELECT label FROM tl_form_field WHERE tl_form_field.id=tl_lead_data.field_id) AS fieldLabel\n            FROM tl_lead_data\n            WHERE pid=?\n        ")->execute($leadId);
     // Generate the form data and labels
     while ($leadDataCollection->next()) {
         $data[$leadDataCollection->name] = $leadDataCollection->value;
         $labels[$leadDataCollection->name] = $leadDataCollection->fieldLabel ?: $leadDataCollection->name;
     }
     $formHelper = new \NotificationCenter\tl_form();
     // Send the notification
     $result = $notification->send($formHelper->generateTokens($data, $form->row(), array(), $labels));
     return !in_array(false, $result);
 }