Statistics
280
2
0
16d
Badges
Tags
forms
Dependencies

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) to Nette\Forms\Container.

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

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

Example:


trait TFormControls
{

    use Nepada\Bridges\EmailAddressInputForms\TEmailAddressInput;

    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 TFormControls;

}

class Form extends Nette\Forms\Form
{

    use TFormControls;

}

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(EmailAddress::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');
  • 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.

Is this addon outdated? Did you find an issue? Please report it.

Componette Componette admin@componette.com