/**
  * Returns Data Attribute Array for JS validation with parsley.js
  *
  * @param Field $field
  * @param array $additionalAttributes To add further attributes
  * @param mixed $iteration Iterationarray for Multi Fields (Radio, Check, ...)
  * @return array for data attributes
  */
 public function render(Field $field, $additionalAttributes = array(), $iteration = null)
 {
     $additionalAttributes = parent::render($field, $additionalAttributes, $iteration);
     if ($this->isClientValidationEnabled()) {
         $additionalAttributes['data-parsley-equalto'] = '#powermail_field_' . $field->getMarker();
         $additionalAttributes['data-parsley-equalto-message'] = LocalizationUtility::translate('validationerror_password');
     }
     return $additionalAttributes;
 }
 /**
  * Generate Monthnames from locallang
  *
  * @return string
  */
 protected function getMonthNames()
 {
     $months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
     $monthArray = [];
     foreach ($months as $month) {
         $monthArray[] = LocalizationUtility::translate('datepicker_month_' . $month);
     }
     return implode(',', $monthArray);
 }
 /**
  * Set mandatory attributes
  *
  * @param array &$additionalAttributes
  * @param Field $field
  * @return void
  */
 protected function addMandatoryAttributes(&$additionalAttributes, Field $field = null)
 {
     if ($field !== null && $field->getMandatory()) {
         if ($this->isNativeValidationEnabled()) {
             $additionalAttributes['required'] = 'required';
         } else {
             if ($this->isClientValidationEnabled()) {
                 $additionalAttributes['data-parsley-required'] = 'true';
             }
         }
         if ($this->isClientValidationEnabled()) {
             $additionalAttributes['data-parsley-required-message'] = LocalizationUtility::translate('validationerror_mandatory');
             $additionalAttributes['data-parsley-trigger'] = 'change';
         }
     }
 }
 /**
  * Returns Data Attribute Array for JS validation with parsley.js
  *
  * @param Field $field
  * @param array $additionalAttributes To add further attributes
  * @param mixed $iteration Iterationarray for Multi Fields (Radio, Check, ...)
  * @return array for data attributes
  */
 public function render(Field $field, $additionalAttributes = array(), $iteration = null)
 {
     if ($field->getType() !== 'captcha') {
         return $additionalAttributes;
     }
     $dataArray = parent::render($field, $additionalAttributes, $iteration);
     if ($this->isNativeValidationEnabled()) {
         $dataArray['required'] = 'required';
     } elseif ($this->isClientValidationEnabled()) {
         $dataArray['data-parsley-required'] = 'true';
     }
     if ($this->isClientValidationEnabled()) {
         $dataArray['data-parsley-errors-container'] = '.powermail_field_error_container_' . $field->getMarker();
         $dataArray['data-parsley-class-handler'] = '.powermail_fieldwrap_' . $field->getUid() . ' > div';
         $dataArray['data-parsley-required-message'] = LocalizationUtility::translate('validationerror_mandatory');
     }
     return $dataArray;
 }
 /**
  * Array for multiple upload
  *
  * @param Field $field
  * @param array $additionalAttributes To add further attributes
  * @return array
  */
 public function render(Field $field, $additionalAttributes = [])
 {
     $this->addMandatoryAttributes($additionalAttributes, $field);
     if ($field->getMultiselectForField()) {
         $additionalAttributes['multiple'] = 'multiple';
     }
     if (!empty($this->settings['misc']['file']['extension'])) {
         $additionalAttributes['accept'] = $this->getDottedListOfExtensions($this->settings['misc']['file']['extension']);
     }
     if ($this->isClientValidationEnabled()) {
         if (!empty($this->settings['misc']['file']['size'])) {
             $additionalAttributes['data-parsley-powermailfilesize'] = (int) $this->settings['misc']['file']['size'] . ',' . $field->getMarker();
             $additionalAttributes['data-parsley-powermailfilesize-message'] = LocalizationUtility::translate('validationerror_upload_size');
         }
         if (!empty($this->settings['misc']['file']['extension'])) {
             $additionalAttributes['data-parsley-powermailfileextensions'] = $field->getMarker();
             $additionalAttributes['data-parsley-powermailfileextensions-message'] = LocalizationUtility::translate('validationerror_upload_extension');
         }
     }
     return $additionalAttributes;
 }
 /**
  * Returns sendername from a couple of arguments
  *
  * @param Mail $mail Given Params
  * @param string|array $default String as default or cObject array
  * @param string $glue
  * @return string Sender Name
  */
 public function getSenderNameFromArguments(Mail $mail, $default = null, $glue = ' ')
 {
     $name = '';
     foreach ($mail->getAnswers() as $answer) {
         if (method_exists($answer->getField(), 'getUid') && $answer->getField()->getSenderName()) {
             if (!is_array($answer->getValue())) {
                 $value = $answer->getValue();
             } else {
                 $value = implode($glue, $answer->getValue());
             }
             $name .= $value . $glue;
         }
     }
     if (!trim($name) && $default) {
         if (!is_array($default)) {
             $name = $default;
         } else {
             /** @var ContentObjectRenderer $contentObject */
             $contentObject = GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer');
             $name = $contentObject->cObjGetSingle($default[0][$default[1]], $default[0][$default[1] . '.']);
         }
     }
     if (empty($name) && !empty($GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'])) {
         $name = $GLOBALS['TYPO3_CONF_VARS']['MAIL']['defaultMailFromName'];
     }
     if (!trim($name)) {
         $name = LocalizationUtility::translate('error_no_sender_name');
     }
     return trim($name);
 }
Esempio n. 7
0
 /**
  * Initialize Action
  *
  * @return void
  */
 public function initializeAction()
 {
     parent::initializeAction();
     if (!isset($this->settings['staticTemplate'])) {
         $this->controllerContext = $this->buildControllerContext();
         $this->addFlashMessage(LocalizationUtility::translate('error_no_typoscript'), '', AbstractMessage::ERROR);
     }
 }
 /**
  * Set different validation attributes
  *
  * @param array &$additionalAttributes
  * @param Field $field
  * @return void
  */
 protected function addValidationAttributes(&$additionalAttributes, $field)
 {
     if ($field->getType() !== 'input' && $field->getType() !== 'textarea') {
         return;
     }
     switch ($field->getValidation()) {
         /**
          * EMAIL (+html5)
          *
          * html5 example: <input type="email" />
          * javascript example: <input type="text" data-parsley-type="email" />
          */
         case 1:
             if ($this->isClientValidationEnabled() && !$this->isNativeValidationEnabled()) {
                 $additionalAttributes['data-parsley-type'] = 'email';
             }
             break;
             /**
              * URL (+html5)
              *
              * html5 example: <input type="url" />
              * javascript example: <input type="text" data-parsley-type="url" />
              */
         /**
          * URL (+html5)
          *
          * html5 example: <input type="url" />
          * javascript example: <input type="text" data-parsley-type="url" />
          */
         case 2:
             if ($this->isClientValidationEnabled() && !$this->isNativeValidationEnabled()) {
                 $additionalAttributes['data-parsley-type'] = 'url';
             }
             break;
             /**
              * PHONE (+html5)
              *        01234567890
              *        0123 4567890
              *        0123 456 789
              *        (0123) 45678 - 90
              *        0012 345 678 9012
              *        0012 (0)345 / 67890 - 12
              *        +123456789012
              *        +12 345 678 9012
              *        +12 3456 7890123
              *        +49 (0) 123 3456789
              *        +49 (0)123 / 34567 - 89
              *
              * html5 example:
              *        <input type="text"
              *            pattern="/^(\+\d{1,4}|0+\d{1,5}|\(\d{1,5})[\d\s\/\(\)-]*\d+$/" />
              * javascript example:
              *        <input ... data-parsley-pattern=
              *            "/^(\+\d{1,4}|0+\d{1,5}|\(\d{1,5})[\d\s\/\(\)-]*\d+$/" />
              */
         /**
          * PHONE (+html5)
          *        01234567890
          *        0123 4567890
          *        0123 456 789
          *        (0123) 45678 - 90
          *        0012 345 678 9012
          *        0012 (0)345 / 67890 - 12
          *        +123456789012
          *        +12 345 678 9012
          *        +12 3456 7890123
          *        +49 (0) 123 3456789
          *        +49 (0)123 / 34567 - 89
          *
          * html5 example:
          *        <input type="text"
          *            pattern="/^(\+\d{1,4}|0+\d{1,5}|\(\d{1,5})[\d\s\/\(\)-]*\d+$/" />
          * javascript example:
          *        <input ... data-parsley-pattern=
          *            "/^(\+\d{1,4}|0+\d{1,5}|\(\d{1,5})[\d\s\/\(\)-]*\d+$/" />
          */
         case 3:
             $pattern = '^(\\+\\d{1,4}|0+\\d{1,5}|\\(\\d{1,5})[\\d\\s\\/\\(\\)-]*\\d+$';
             if ($this->isNativeValidationEnabled()) {
                 $additionalAttributes['pattern'] = $pattern;
             } else {
                 if ($this->isClientValidationEnabled()) {
                     $additionalAttributes['data-parsley-pattern'] = $pattern;
                 }
             }
             break;
             /**
              * NUMBER/INTEGER (+html5)
              *
              * html5 example: <input type="number" />
              * javascript example: <input type="text" data-parsley-type="integer" />
              */
         /**
          * NUMBER/INTEGER (+html5)
          *
          * html5 example: <input type="number" />
          * javascript example: <input type="text" data-parsley-type="integer" />
          */
         case 4:
             if ($this->isClientValidationEnabled() && !$this->isNativeValidationEnabled()) {
                 $additionalAttributes['data-parsley-type'] = 'integer';
             }
             break;
             /**
              * LETTERS (+html5)
              *
              * html5 example: <input type="text" pattern="[a-zA-Z]." />
              * javascript example: <input type="text" data-parsley-pattern="[a-zA-Z]." />
              */
         /**
          * LETTERS (+html5)
          *
          * html5 example: <input type="text" pattern="[a-zA-Z]." />
          * javascript example: <input type="text" data-parsley-pattern="[a-zA-Z]." />
          */
         case 5:
             if ($this->isNativeValidationEnabled()) {
                 $additionalAttributes['pattern'] = '[A-Za-z]+';
             } else {
                 if ($this->isClientValidationEnabled()) {
                     $additionalAttributes['data-parsley-pattern'] = '[a-zA-Z]+';
                 }
             }
             break;
             /**
              * MIN NUMBER (+html5)
              *
              * Note: Field validation_configuration for editors viewable
              * html5 example: <input type="text" min="6" />
              * javascript example: <input type="text" data-parsley-min="6" />
              */
         /**
          * MIN NUMBER (+html5)
          *
          * Note: Field validation_configuration for editors viewable
          * html5 example: <input type="text" min="6" />
          * javascript example: <input type="text" data-parsley-min="6" />
          */
         case 6:
             if ($this->isNativeValidationEnabled()) {
                 $additionalAttributes['min'] = $field->getValidationConfiguration();
             } else {
                 if ($this->isClientValidationEnabled()) {
                     $additionalAttributes['data-parsley-min'] = $field->getValidationConfiguration();
                 }
             }
             break;
             /**
              * MAX NUMBER (+html5)
              *
              * Note: Field validation_configuration for editors viewable
              * html5 example: <input type="text" max="12" />
              * javascript example: <input type="text" data-parsley-max="12" />
              */
         /**
          * MAX NUMBER (+html5)
          *
          * Note: Field validation_configuration for editors viewable
          * html5 example: <input type="text" max="12" />
          * javascript example: <input type="text" data-parsley-max="12" />
          */
         case 7:
             if ($this->isNativeValidationEnabled()) {
                 $additionalAttributes['max'] = $field->getValidationConfiguration();
             } else {
                 if ($this->isClientValidationEnabled()) {
                     $additionalAttributes['data-parsley-max'] = $field->getValidationConfiguration();
                 }
             }
             break;
             /**
              * RANGE (+html5)
              *
              * Note: Field validation_configuration for editors viewable
              * html5 example: <input type="range" min="1" max="10" />
              * javascript example:
              *        <input type="text" data-parsley-type="range" min="1" max="10" />
              */
         /**
          * RANGE (+html5)
          *
          * Note: Field validation_configuration for editors viewable
          * html5 example: <input type="range" min="1" max="10" />
          * javascript example:
          *        <input type="text" data-parsley-type="range" min="1" max="10" />
          */
         case 8:
             $values = GeneralUtility::trimExplode(',', $field->getValidationConfiguration(), true);
             if ((int) $values[0] <= 0) {
                 break;
             }
             if (!isset($values[1])) {
                 $values[1] = $values[0];
                 $values[0] = 1;
             }
             if ($this->isNativeValidationEnabled()) {
                 $additionalAttributes['min'] = (int) $values[0];
                 $additionalAttributes['max'] = (int) $values[1];
             } else {
                 if ($this->isClientValidationEnabled()) {
                     $additionalAttributes['data-parsley-min'] = (int) $values[0];
                     $additionalAttributes['data-parsley-max'] = (int) $values[1];
                 }
             }
             break;
             /**
              * LENGTH
              *
              * Note: Field validation_configuration for editors viewable
              * javascript example:
              *        <input type="text" data-parsley-length="[6, 10]" />
              */
         /**
          * LENGTH
          *
          * Note: Field validation_configuration for editors viewable
          * javascript example:
          *        <input type="text" data-parsley-length="[6, 10]" />
          */
         case 9:
             $values = GeneralUtility::trimExplode(',', $field->getValidationConfiguration(), true);
             if ((int) $values[0] <= 0) {
                 break;
             }
             if (!isset($values[1])) {
                 $values[1] = (int) $values[0];
                 $values[0] = 1;
             }
             if ($this->isClientValidationEnabled()) {
                 $additionalAttributes['data-parsley-length'] = '[' . implode(', ', $values) . ']';
             }
             break;
             /**
              * PATTERN (+html5)
              *
              * Note: Field validation_configuration for editors viewable
              * html5 example: <input type="text" pattern="https?://.+" />
              * javascript example:
              *        <input type="text" data-parsley-pattern="https?://.+" />
              */
         /**
          * PATTERN (+html5)
          *
          * Note: Field validation_configuration for editors viewable
          * html5 example: <input type="text" pattern="https?://.+" />
          * javascript example:
          *        <input type="text" data-parsley-pattern="https?://.+" />
          */
         case 10:
             if ($this->isNativeValidationEnabled()) {
                 $additionalAttributes['pattern'] = $field->getValidationConfiguration();
             } else {
                 if ($this->isClientValidationEnabled()) {
                     $additionalAttributes['data-parsley-pattern'] = $field->getValidationConfiguration();
                 }
             }
             break;
             /**
              * Custom Validation Attribute
              *
              * If CustomValidation was added via Page TSConfig
              *        tx_powermail.flexForm.validation.addFieldOptions.100 = New Validation
              *
              * <input type="text" data-parsley-custom100="1" />
              */
         /**
          * Custom Validation Attribute
          *
          * If CustomValidation was added via Page TSConfig
          *        tx_powermail.flexForm.validation.addFieldOptions.100 = New Validation
          *
          * <input type="text" data-parsley-custom100="1" />
          */
         default:
             if ($field->getValidation() && $this->isClientValidationEnabled()) {
                 $value = 1;
                 if ($field->getValidationConfiguration()) {
                     $value = $field->getValidationConfiguration();
                 }
                 $additionalAttributes['data-parsley-custom' . $field->getValidation()] = $value;
             }
     }
     // set errormessage if javascript validation active
     if ($field->getValidation() && $this->isClientValidationEnabled()) {
         $additionalAttributes['data-parsley-error-message'] = LocalizationUtility::translate('validationerror_validation.' . $field->getValidation());
     }
 }
Esempio n. 9
0
 /**
  * Sets the value
  *
  * @param mixed $value
  * @dontvalidate $value
  * @return void
  */
 public function setValue($value)
 {
     // if array, encode to string
     if (is_array($value)) {
         $value = json_encode($value);
     }
     // if date, get timestamp (datepicker)
     if ($this->isTypeDateForDate($value)) {
         if (empty($this->translateFormat)) {
             $format = LocalizationUtility::translate('datepicker_format_' . $this->getField()->getDatepickerSettings());
         } else {
             $format = $this->translateFormat;
         }
         $date = \DateTime::createFromFormat($format, $value);
         if ($date) {
             if ($this->getField()->getDatepickerSettings() === 'date') {
                 $date->setTime(0, 0, 0);
             }
             $value = $date->getTimestamp();
         } else {
             // fallback html5 date field - always Y-m-d H:i
             $date = new \DateTime($value);
             if ($date) {
                 if ($this->getField()->getDatepickerSettings() === 'date') {
                     $date->setTime(0, 0, 0);
                 }
                 $value = $date->getTimestamp();
             }
         }
     }
     $this->value = $value;
 }
 /**
  * Returns sendername from a couple of arguments
  *
  * @param Mail $mail Given Params
  * @param string|array $default String as default or cObject array
  * @param string $glue
  * @return string Sender Name
  */
 public function getSenderNameFromArguments(Mail $mail, $default = null, $glue = ' ')
 {
     $name = '';
     foreach ($mail->getAnswers() as $answer) {
         /** @var Answer $answer */
         if (method_exists($answer->getField(), 'getUid') && $answer->getField()->isSenderName()) {
             if (!is_array($answer->getValue())) {
                 $value = $answer->getValue();
             } else {
                 $value = implode($glue, $answer->getValue());
             }
             $name .= $value . $glue;
         }
     }
     if (!trim($name) && $default) {
         if (!is_array($default)) {
             $name = $default;
         } else {
             /** @var ContentObjectRenderer $contentObject */
             $contentObject = GeneralUtility::makeInstance(ObjectManager::class)->get(ContentObjectRenderer::class);
             $name = $contentObject->cObjGetSingle($default[0][$default[1]], $default[0][$default[1] . '.']);
         }
     }
     if (empty($name) && !empty(ConfigurationUtility::getDefaultMailFromName())) {
         $name = ConfigurationUtility::getDefaultMailFromName();
     }
     if (!trim($name)) {
         $name = LocalizationUtility::translate('error_no_sender_name');
     }
     return trim($name);
 }