--- /dev/null
+{include file='__formFieldHeader'}
+
+<input type="email" {*
+ *}id="{@$field->getPrefixedId()}" {*
+ *}name="{@$field->getPrefixedId()}" {*
+ *}value="{if !$field->isI18n() || !$field->hasI18nValues()}{$field->getValue()}{/if}" {*
+ *}class="long"{*
+ *}{if $field->isAutofocused()} autofocus{/if}{*
+ *}{if $field->isRequired()} required{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getMaximumLength() !== null} maxlength="{$field->getMaximumLength()}"{/if}{*
+ *}{if $field->getPlaceholder() !== null} placeholder="{$field->getPlaceholder()}"{/if}{*
+ *}{if $field->getDocument()->isAjax()} data-dialog-submit-on-enter="true"{/if}{*
+*}>
+
+{if $field->isI18n()}
+ {include file='multipleLanguageInputJavascript'}
+{/if}
+
+{include file='__formFieldFooter'}
"__booleanFormField",
"__contentLanguageFormField",
"__dateFormField",
+ "__emailFormField",
"__emptyFormFieldDependency",
"__form",
"__formButton",
--- /dev/null
+{include file='__formFieldHeader'}
+
+<input type="email" {*
+ *}id="{@$field->getPrefixedId()}" {*
+ *}name="{@$field->getPrefixedId()}" {*
+ *}value="{if !$field->isI18n() || !$field->hasI18nValues()}{$field->getValue()}{/if}" {*
+ *}class="long"{*
+ *}{if $field->isAutofocused()} autofocus{/if}{*
+ *}{if $field->isRequired()} required{/if}{*
+ *}{if $field->isImmutable()} disabled{/if}{*
+ *}{if $field->getMaximumLength() !== null} maxlength="{$field->getMaximumLength()}"{/if}{*
+ *}{if $field->getPlaceholder() !== null} placeholder="{$field->getPlaceholder()}"{/if}{*
+ *}{if $field->getDocument()->isAjax()} data-dialog-submit-on-enter="true"{/if}{*
+*}>
+
+{if $field->isI18n()}
+ {include file='multipleLanguageInputJavascript'}
+{/if}
+
+{include file='__formFieldFooter'}
--- /dev/null
+<?php
+namespace wcf\system\form\builder\field;
+use wcf\data\language\Language;
+use wcf\system\exception\UserInputException;
+use wcf\system\form\builder\field\validation\FormFieldValidationError;
+use wcf\system\language\LanguageFactory;
+use wcf\util\UserUtil;
+
+/**
+ * Implementation of a form field for an email address.
+ *
+ * The default label of fields of this class is `wcf.form.field.email`.
+ *
+ * @author Matthias Schmidt
+ * @copyright 2001-2019 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Form\Builder\Field
+ * @since 5.2
+ */
+class EmailFormField extends AbstractFormField implements IAutoFocusFormField, II18nFormField, IImmutableFormField, IMaximumLengthFormField, IPlaceholderFormField {
+ use TAutoFocusFormField;
+ use TImmutableFormField;
+ use TI18nFormField {
+ validate as protected i18nValidate;
+ }
+ use TMaximumLengthFormField;
+ use TPlaceholderFormField;
+
+ /**
+ * @inheritDoc
+ */
+ protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Value';
+
+ /**
+ * @inheritDoc
+ */
+ protected $templateName = '__emailFormField';
+
+ /**
+ * @inheritDoc
+ */
+ public function __construct() {
+ $this->label('wcf.form.field.email');
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public function validate() {
+ if ($this->isI18n()) {
+ $this->i18nValidate();
+
+ if (empty($this->getValidationErrors())) {
+ $value = $this->getValue();
+ if ($this->hasPlainValue()) {
+ $this->validateEmail($value);
+ }
+ else {
+ foreach ($value as $languageID => $languageValue) {
+ $this->validateEmail($languageValue, LanguageFactory::getInstance()->getLanguage($languageID));
+ }
+ }
+ }
+ }
+ else {
+ if ($this->isRequired() && ($this->getValue() === null || $this->getValue() === '')) {
+ $this->addValidationError(new FormFieldValidationError('empty'));
+ }
+ else {
+ $this->validateEmail($this->getValue());
+ }
+ }
+
+ parent::validate();
+ }
+
+ /**
+ * Validates the given email address in the given language.
+ *
+ * @param string $email validated email address
+ * @param null|Language $language language of validated email address or `null` for monolingual email address
+ */
+ protected function validateEmail($email, Language $language = null) {
+ if ($email === null || $email === '') {
+ return;
+ }
+
+ if (!UserUtil::isValidEmail($email)) {
+ $this->addValidationError(new FormFieldValidationError(
+ 'invalidEmail',
+ 'wcf.form.field.email.error.invalidEmail',
+ ['language' => $language]
+ ));
+ }
+ else {
+ $this->validateMaximumLength(
+ $email,
+ $language,
+ 'wcf.form.field.email.error.maximumLength'
+ );
+ }
+ }
+}
/**
* Validates the maximum length of the given text.
*
- * @param string $text validated text
- * @param null|Language $language language of the validated text
+ * @param string $text validated text
+ * @param null|Language $language language of the validated text
+ * @param string $errorLanguageItem
*/
- public function validateMaximumLength($text, Language $language = null) {
+ public function validateMaximumLength($text, Language $language = null, $errorLanguageItem = 'wcf.form.field.text.error.maximumLength') {
if ($this->getMaximumLength() !== null && mb_strlen($text) > $this->getMaximumLength()) {
$this->addValidationError(new FormFieldValidationError(
'maximumLength',
- 'wcf.form.field.text.error.maximumLength',
+ $errorLanguageItem,
[
'language' => $language,
'length' => mb_strlen($text),
<item name="wcf.form.field.date.error.latestDate"><![CDATA[Der angegebene Wert darf nicht später sein als {$latestDate}.]]></item>
<item name="wcf.form.field.itemList.error.maximumMultiples"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du darfst{else}Sie dürfen{/if} nicht mehr als {#$maximumCount} {if $maximumCount == 1}Eintrag{else}Einträge{/if} angeben, es wurde{if $count != 1}n{/if} aber {#$count} {if $count == 1}Eintrag{else}Einträge{/if} angegeben.]]></item>
<item name="wcf.form.field.itemList.error.minimumMultiples"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du musst{else}Sie müssen{/if} zumindest {#$minimumCount} {if $minimumCount == 1}Eintrag{else}Einträge{/if} angeben, es wurde{if $count != 1}n{/if} aber nur {#$count} {if $count == 1}Eintrag{else}Einträge{/if} angegeben.]]></item>
+ <item name="wcf.form.field.email"><![CDATA[E-Mail-Adresse]]></item>
+ <item name="wcf.form.field.email.error.invalidEmail"><![CDATA[Die Eingabe ist keine gültige E-Mail-Adresse.]]></item>
+ <item name="wcf.form.field.email.error.maximumLength"><![CDATA[Die angegebene E-Mail-Adresse{if $language} für die Sprache „{$language}“{/if} umfasst {#$length} Zeichen, sie darf aber nicht länger als {#$maximumLength} Zeichen sein.]]></item>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Titelbild]]></item>
<item name="wcf.form.field.date.error.latestDate"><![CDATA[The entered value may not be later than {$latestDate}.]]></item>
<item name="wcf.form.field.itemList.error.maximumMultiples"><![CDATA[You may not enter more than {#$maximumCount} {if $maximumCount == 1}entry{else}entries{/if} but {#$count} {if $count == 1}entry is{else}entries are{/if} given.]]></item>
<item name="wcf.form.field.itemList.error.minimumMultiples"><![CDATA[You have to entered at least {#$minimumCount} {if $minimumCount == 1}entry{else}entries{/if} but only {#$count} {if $count == 1}entry is{else}entries are{/if} given.]]></item>
+ <item name="wcf.form.field.email"><![CDATA[Email Address]]></item>
+ <item name="wcf.form.field.email.error.invalidEmail"><![CDATA[The entered text is no valid email address.]]></item>
+ <item name="wcf.form.field.email.error.maximumLength"><![CDATA[The entered email address{if $language|isset} for language “{$language}”{/if} contains {#$length} character{if $length !== 1}s{/if} but it may not be longer than {#$maximumLength} character{if $maximumLength !== 1}s{/if}.]]></item>
</category>
<category name="wcf.image">
<item name="wcf.image.coverPhoto"><![CDATA[Cover Photo]]></item>