<commit_before>.. _user-guide-forms-and-actions:

#################
Forms and actions
#################

Adding new albums
-----------------

We can now code up the functionality to add new albums. There are two bits to
this part:

* Display a form for user to provide details
* Process the form submission and store to database
  
We use ``Zend\Form`` to do this. The ``Zend\Form`` component manages the form
and for validation, we add a ``Zend\InputFilter`` to our ``Album`` entity. We
start by creating a new class ``Album\Form\AlbumForm`` that extends from
``Zend\Form\Form`` to define our form. The class is stored in the
``AlbumForm.php`` file within the ``module/Album/src/Album/Form`` directory.

Create this file file now:

.. code-block:: php

    // module/Album/src/Album/Form/AlbumForm.php:
    namespace Album\Form;

    use Zend\Form\Form;

    class AlbumForm extends Form
    {
        public function __construct($name = null)
        {
            // we want to ignore the name passed
            parent::__construct('album');
            $this->setAttribute('method', 'post');
            $this->add(array(
                'name' => 'id',
                'type' => 'Hidden',
            ));
            $this->add(array(
                'name' => 'artist',
                'type' => 'Text',
                'options' => array(
                    'label' => 'Artist',<commit_msg>Update forms-and-actions.rst<commit_after>.. _user-guide-forms-and-actions:

#################
Formularios y acciones
#################

Agregando nuevos albumes
-----------------

Nosotros ahora podemos codificar la funcinalidad de agregar nuevos albumes. Hay dos partes para esto:

* Mostrar un formularo para el usuario para proveer detalles.
* Procesar el envío del formulario y almacenarlo en la base de datos.
  
Nostros usaremos ``Zend\Form`` para hacer esto. El componente ``Zend\Form`` maneja el formulario y su validación, nosotros agregaremos un ``Zend\InputFilter`` a nuestra entidad ``Album``. Nosotros comenzaremos creando una nueva clase ``Album\Form\Album\Form`` esta se extiende de ``Zend\Form\Form`` para definir nuestro formulario. La clase se almacena en el archivo ``AlbumForm.php`` dentro del directorio ``module/Album/src/Album/Form``.

Create this file file now:

.. code-block:: php

    // module/Album/src/Album/Form/AlbumForm.php:
    namespace Album\Form;

    use Zend\Form\Form;

    class AlbumForm extends Form
    {
        public function __construct($name = null)
        {
            // we want to ignore the name passed
            parent::__construct('album');
            $this->setAttribute('method', 'post');
            $this->add(array(
                'name' => 'id',
                'type' => 'Hidden',
            ));
            $this->add(array(
                'name' => 'artist',
                'type' => 'Text',
                'options' => array(
                    'label' => 'Artist',
{'fraction_non_alphanumeric': 0.14688881332879972, 'fraction_numerical': 0.0, 'mean_word_length': 2.358447488584475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '523729', 'n_tokens_mistral': 877, 'n_tokens_neox': 830, 'n_words': 276}