Commit e350e867 authored by Olle Haerstedt's avatar Olle Haerstedt Committed by Markus Klein
Browse files

[FEATURE] A new eval option in TCA: email

Add a new eval option called 'email' to validate e-mail addresses.
If validation fails, a flash error message will be shown.

Resolves: #62147
Releases: master
Change-Id: Ie3885aa55a3fde95832fec163bc9347f06b4f54b
Reviewed-on: http://review.typo3.org/33251


Reviewed-by: Stefan Froemken's avatarStefan Froemken <froemken@gmail.com>
Tested-by: Stefan Froemken's avatarStefan Froemken <froemken@gmail.com>
Reviewed-by: default avatarMarkus Klein <klein.t3@reelworx.at>
Tested-by: default avatarMarkus Klein <klein.t3@reelworx.at>
parent e2a52253
......@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\DataHandling;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Versioning\VersionState;
......@@ -2506,6 +2507,9 @@ class DataHandler {
$value = GeneralUtility::idnaEncode($value);
}
break;
case 'email':
$this->checkValue_input_ValidateEmail($value, $set);
break;
default:
$evalObj = GeneralUtility::getUserObj($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tce']['formevals'][$func] . ':&' . $func);
if (is_object($evalObj) && method_exists($evalObj, 'evaluateFieldValue')) {
......@@ -2519,6 +2523,35 @@ class DataHandler {
return $res;
}
/**
* If $value is not a valid e-mail address,
* $set will be set to false and a flash error
* message will be added
*
* @param string $value Value to evaluate
* @param bool $set TRUE if an update should be done
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Exception
* @return void
*/
protected function checkValue_input_ValidateEmail($value, &$set) {
if (GeneralUtility::validEmail($value)) {
return;
}
$set = FALSE;
/** @var FlashMessage $message */
$message = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
sprintf($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:error.invalidEmail'), $value),
'', // header is optional
FlashMessage::ERROR,
TRUE // whether message should be stored in session
);
/** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
$flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
$flashMessageService->getMessageQueueByIdentifier()->enqueue($message);
}
/**
* Returns data for group/db and select fields
*
......@@ -7130,7 +7163,7 @@ class DataHandler {
while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res_log)) {
$log_data = unserialize($row['log_data']);
$msg = $row['error'] . ': ' . sprintf($row['details'], $log_data[0], $log_data[1], $log_data[2], $log_data[3], $log_data[4]);
$flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($msg), '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR, TRUE);
$flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', htmlspecialchars($msg), '', FlashMessage::ERROR, TRUE);
/** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
$flashMessageService = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessageService');
/** @var $defaultFlashMessageQueue \TYPO3\CMS\Core\Messaging\FlashMessageQueue */
......
===============================================
Feature: #62147 - New eval option in TCA: email
===============================================
Description
===========
A new option is added to the eval field: email. This will
check on server side if entered value is a valid e-mail address.
If not, a flash error message will be shown.
Usage:
::
'email' => array(
'exclude' => 1,
'label' => 'LLL:EXT:wd_products/Resources/Private/Language/locallang_db.xlf:tx_wdproducts_domain_model_contactperson.email',
'config' => array(
'type' => 'input',
'size' => 30,
'eval' => 'email,trim'
),
)
..
Impact
======
Users don't have to write their own validation classes for e-mail validation.
......@@ -1089,6 +1089,9 @@ Check also the following points:\n
<trans-unit id="error.items_proc_func_error" xml:space="preserve">
<source>An error occurred trying to process items for field "%1$s" (%2$s).</source>
</trans-unit>
<trans-unit id="error.invalidEmail" xml:space="preserve">
<source>"%s" is not a valid e-mail address.</source>
</trans-unit>
</body>
</file>
</xliff>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment