PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/languages/en/modules/zend.form.element.email.rst

https://github.com/arthead/zf2-documentation
ReStructuredText | 94 lines | 66 code | 28 blank | 0 comment | 0 complexity | 57f954ea7efff18568b464d6301f9aeb MD5 | raw file
Possible License(s): BSD-3-Clause
  1. .. _zend.form.element.email:
  2. Email Element
  3. ^^^^^^^^^^^^^
  4. ``Zend\Form\Element\Email`` is meant to be paired with the ``Zend\Form\View\Helper\FormEmail`` for `HTML5 inputs with
  5. type email`_. This element adds filters and validators to it's input filter specification in order to validate
  6. `HTML5 valid email address`_ on the server.
  7. .. _zend.form.element.email.usage:
  8. Basic Usage
  9. """""""""""
  10. This element automatically adds a ``"type"`` attribute of value ``"email"``.
  11. .. code-block:: php
  12. :linenos:
  13. use Zend\Form\Element;
  14. use Zend\Form\Form;
  15. $form = new Form('my-form');
  16. // Single email address
  17. $email = new Element\Email('email');
  18. $email->setLabel('Email Address')
  19. $form->add($email);
  20. // Comma separated list of emails
  21. $emails = new Element\Email('emails');
  22. $emails
  23. ->setLabel('Email Addresses')
  24. ->setAttribute('multiple', true);
  25. $form->add($emails);
  26. Here is with the array notation:
  27. .. code-block:: php
  28. :linenos:
  29. use Zend\Form\Form;
  30. $form = new Form('my-form');
  31. $form->add(array(
  32. 'type' => 'Zend\Form\Element\Email',
  33. 'name' => 'email',
  34. 'options' => array(
  35. 'label' => 'Email Address'
  36. ),
  37. ));
  38. $form->add(array(
  39. 'type' => 'Zend\Form\Element\Email',
  40. 'name' => 'emails',
  41. 'options' => array(
  42. 'label' => 'Email Addresses'
  43. ),
  44. 'attributes' => array(
  45. 'multiple' => true
  46. )
  47. ));
  48. .. note::
  49. Note: the ``multiple`` attribute should be set prior to calling Zend\\Form::prepare(). Otherwise, the default
  50. input specification for the element may not contain the correct validation rules.
  51. .. _zend.form.element.email.methods:
  52. Public Methods
  53. """"""""""""""
  54. The following methods are in addition to the inherited :ref:`methods of Zend\\Form\\Element
  55. <zend.form.element.methods>`.
  56. .. function:: getInputSpecification()
  57. :noindex:
  58. Returns a input filter specification, which includes a ``Zend\Filter\StringTrim`` filter, and a validator based
  59. on the ``multiple`` attribute.
  60. If the ``multiple`` attribute is unset or false, a ``Zend\Validator\Regex`` validator will be added to validate
  61. a single email address.
  62. If the ``multiple`` attribute is true, a ``Zend\Validator\Explode`` validator will be added to ensure the input
  63. string value is split by commas before validating each email address with ``Zend\Validator\Regex``.
  64. :rtype: array
  65. .. _`HTML5 inputs with type email`: http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-(type=email)
  66. .. _`HTML5 valid email address`: http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address