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

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

https://github.com/Xerkus/zf2-documentation
ReStructuredText | 121 lines | 83 code | 38 blank | 0 comment | 0 complexity | de3710ed6436b2ac70a54849b77fff42 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. :orphan:
  2. .. _zend.form.element.email:
  3. Email
  4. ^^^^^
  5. ``Zend\Form\Element\Email`` is meant to be paired with the ``Zend\Form\View\Helper\FormEmail`` for `HTML5 inputs with
  6. type email`_. This element adds filters and validators to it's input filter specification in order to validate
  7. `HTML5 valid email address`_ on the server.
  8. .. _zend.form.element.email.usage:
  9. .. rubric:: Basic Usage
  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. .. rubric:: Public Methods
  53. The following methods are in addition to the inherited :ref:`methods of Zend\\Form\\Element
  54. <zend.form.element.methods>`.
  55. .. function:: getInputSpecification()
  56. :noindex:
  57. Returns a input filter specification, which includes a ``Zend\Filter\StringTrim`` filter, and a validator based
  58. on the ``multiple`` attribute.
  59. If the ``multiple`` attribute is unset or false, a ``Zend\Validator\Regex`` validator will be added to validate
  60. a single email address.
  61. If the ``multiple`` attribute is true, a ``Zend\Validator\Explode`` validator will be added to ensure the input
  62. string value is split by commas before validating each email address with ``Zend\Validator\Regex``.
  63. :rtype: array
  64. .. function:: setValidator(ValidatorInterface $validator)
  65. :noindex:
  66. Sets the primary validator to use for this element
  67. .. function:: getValidator()
  68. :noindex:
  69. Get the primary validator
  70. :rtype: ValidatorInterface
  71. .. function:: setEmailValidator(ValidatorInterface $validator)
  72. :noindex:
  73. Sets the email validator to use for multiple or single email addresses.
  74. .. function:: getEmailValidator()
  75. :noindex:
  76. Get the email validator to use for multiple or single
  77. email addresses.
  78. The default Regex validator in use is to match that of the
  79. browser validation, but you are free to set a different
  80. (more strict) email validator such as ``Zend\Validator\Email``
  81. if you wish.
  82. .. _`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)
  83. .. _`HTML5 valid email address`: http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address