Componette

Componette

nepada

nepada / email-address-input v1.9.1

Email address form input for Nette forms.

download-cloud-line composer require nepada/email-address-input

Email address form input

Build Status Coverage Status Downloads this Month Latest stable

Installation

Via Composer:

$ composer require nepada/email-address-input

Option A: install form container extension method via DI extension

extensions:
    - Nepada\Bridges\EmailAddressInputDI\EmailAddressInputExtension

It will register extension method addEmailAddress($name, $label, $caseSensitive = false) to Nette\Forms\Container.

Option B: use trait in your base form/container class

You can also use EmailAddressInputMixin trait in your base form/container class to add method addEmailAddress($name, $label, $caseSensitive = false).

Example:

trait FormControls
{

    use Nepada\Bridges\EmailAddressInputForms\EmailAddressInputMixin;

    public function addContainer($name)
    {
        $control = new Container;
        $control->setCurrentGroup($this->getCurrentGroup());
        if ($this->currentGroup !== null) {
            $this->currentGroup->add($control);
        }
        return $this[$name] = $control;
    }

}

class Container extends Nette\Forms\Container
{

    use FormControls;

}

class Form extends Nette\Forms\Form
{

    use FormControls;

}

Usage

EmailAddressInput is form control that uses email address value object to represent its value (see nepada/email-address for further details). It automatically validates the user input and getValue() method always returns EmailAddress instance, or null if the input is not filled.

$emailAddressInput = $form->addEmailAddress('E-mail');

// set value using EmailAddress value object
$emailAddressInput->setValue(CaseInsensitiveEmailAddress::fromString('example@example.com'));

// set value using string with a valid email address (it is internally converted to EmailAddress value object)
$emailAddressInput->setValue('example@example.com');

// Get EmailAddress instance for example@example.com
$emailAddressInput->getValue();

// InvalidEmailAddressException is thrown
$emailAddressInput->setValue('42');

Case sensitivity

By default the input returns instance of CaseInsensitiveEmailAddress, i.e. the value object that treats the whole email address as case insensitive.

You can change this behaviour by calling EmailAddressInput::setCaseSensitive(true), or by passing $caseSensitive = true when creating the input. With enabled case sensitivity the input's value will be represented as RfcEmailAddress instance.

For further details see the readme of nepada/email-address.

  • v1.9.1 1.9.1

    • PHP 8.4 compatibility
  • v1.9.0 1.9.0

    • Drop support for PHP <8.1
    • Use PHP8 native typehints
    • Drop useless annotations
    • PHP 8.3 compatibility
  • v1.8.2 1.8.2

    • Support nette/utils 4
  • v1.8.1 1.8.1

    • PHP 8.2 compatibility
  • v1.8.0 1.8.0

    • PHP 8.1 compatibility.
  • v1.7.0 1.7.0

    • PHP 8.0 compatibility.
  • v1.6.0 1.6.0

    • The input value is now represented by CaseInsensitiveEmailAddress (default) or RfcEmailAddress instance depending on the case sensitivity setting of the input.
  • v1.5.1 1.5.1

    • Dropped trait prefix:
      • Nepada\Bridges\EmailAddressInputForms\TEmailAddressInput is deprecated, use Nepada\Bridges\EmailAddressInputForms\EmailAddressInputMixin instead
  • v1.5.0 1.5.0

    Requires PHP >=7.4.

  • v1.4.0 1.4.0

    • Requires PHP >=7.2.
    • PHP 7.4 compatibility.
  • v1.3.0 1.3.0

    • Requires Nette 3.0 (Nette 2.4 support was dropped).
  • v1.2.0 1.2.0

    • Nette 3 compatibility
    • CI improvements
  • v1.1.0 1.1.0

    • Uses nepada/email-address 2.0.
  • v1.0.2 1.0.2

    • Improved method annotations.
  • v1.0.1 1.0.1

    • Fixed handling of empty value.
    • loadHttpData() is no longer responsible for submitted value validation.
  • v1.0.0 1.0.0

    • Initial release for Nette 2.4.
price-tag-2-line

Badges

guide-fill

Dependencies

php (>=7.1.0)
nette/utils (^2.4@dev || ^3.0@dev)
nette/forms (^2.4.6@dev || ^3.0@dev)
Componette Componette felix@nette.org