PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/gullij/zf2-documentation
ReStructuredText | 119 lines | 82 code | 37 blank | 0 comment | 0 complexity | ea428891d93ec0a5c5860506ac806cf1 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. .. _zend.form.element.email:
  2. Email
  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. .. rubric:: Basic Usage
  9. This element automatically adds a ``"type"`` attribute of value ``"email"``.
  10. .. code-block:: php
  11. :linenos:
  12. use Zend\Form\Element;
  13. use Zend\Form\Form;
  14. $form = new Form('my-form');
  15. // Single email address
  16. $email = new Element\Email('email');
  17. $email->setLabel('Email Address')
  18. $form->add($email);
  19. // Comma separated list of emails
  20. $emails = new Element\Email('emails');
  21. $emails
  22. ->setLabel('Email Addresses')
  23. ->setAttribute('multiple', true);
  24. $form->add($emails);
  25. Here is with the array notation:
  26. .. code-block:: php
  27. :linenos:
  28. use Zend\Form\Form;
  29. $form = new Form('my-form');
  30. $form->add(array(
  31. 'type' => 'Zend\Form\Element\Email',
  32. 'name' => 'email',
  33. 'options' => array(
  34. 'label' => 'Email Address'
  35. ),
  36. ));
  37. $form->add(array(
  38. 'type' => 'Zend\Form\Element\Email',
  39. 'name' => 'emails',
  40. 'options' => array(
  41. 'label' => 'Email Addresses'
  42. ),
  43. 'attributes' => array(
  44. 'multiple' => true
  45. )
  46. ));
  47. .. note::
  48. Note: the ``multiple`` attribute should be set prior to calling Zend\\Form::prepare(). Otherwise, the default
  49. input specification for the element may not contain the correct validation rules.
  50. .. _zend.form.element.email.methods:
  51. .. rubric:: Public Methods
  52. The following methods are in addition to the inherited :ref:`methods of Zend\\Form\\Element
  53. <zend.form.element.methods>`.
  54. .. function:: getInputSpecification()
  55. :noindex:
  56. Returns a input filter specification, which includes a ``Zend\Filter\StringTrim`` filter, and a validator based
  57. on the ``multiple`` attribute.
  58. If the ``multiple`` attribute is unset or false, a ``Zend\Validator\Regex`` validator will be added to validate
  59. a single email address.
  60. If the ``multiple`` attribute is true, a ``Zend\Validator\Explode`` validator will be added to ensure the input
  61. string value is split by commas before validating each email address with ``Zend\Validator\Regex``.
  62. :rtype: array
  63. .. function:: setValidator(ValidatorInterface $validator)
  64. :noindex:
  65. Sets the primary validator to use for this element
  66. .. function:: getValidator()
  67. :noindex:
  68. Get the primary validator
  69. :rtype: ValidatorInterface
  70. .. function:: setEmailValidator(ValidatorInterface $validator)
  71. :noindex:
  72. Sets the email validator to use for multiple or single email addresses.
  73. .. function:: getEmailValidator()
  74. :noindex:
  75. Get the email validator to use for multiple or single
  76. email addresses.
  77. The default Regex validator in use is to match that of the
  78. browser validation, but you are free to set a different
  79. (more strict) email validator such as ``Zend\Validator\Email``
  80. if you wish.
  81. .. _`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)
  82. .. _`HTML5 valid email address`: http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#valid-e-mail-address