Sujet : Hoa_Form_element_Other

Il me manquait à chaque fois dans les formulaires pouvoir ajouter du texte entre des champs

Maintenant c'est possible big_smile

1/ Ajouter dans Library/Form/Form.php :

const ELEMENT_OTHER             = 'other';

2/ Ajouter dans Library/Form/Element/Form.php dans la variable privé $matching :

'label'    => 'Label'

3/ Ajouter l'élément suivant dans Library/Element/Other.php

<?php

/**
 * Hoa Framework
 *
 *
 * @license
 *
 * GNU General Public License
 *
 * This file is part of Hoa Open Accessibility.
 * Copyright (c) 2007, 2009 Ivan ENDERLIN. All rights reserved.
 *
 * HOA Open Accessibility is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * HOA Open Accessibility is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HOA Open Accessibility; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 * @category    Framework
 * @package     Hoa_Form
 * @subpackage  Hoa_Form_Element_Textarea
 *
 */

/**
 * Hoa_Framework
 */
require_once 'Framework.php';

/**
 * Hoa_Form_Exception
 */
import('Form.Exception');

/**
 * Hoa_Form_Element_Abstract
 */
import('Form.Element.Abstract');

/**
 * Class Hoa_Form_Element_Textarea.
 *
 * Describe the textarea element.
 *
 * @author      Antoine DARCHE <darche.antoine@gmail.com>
 * @copyright   Copyright (c) 2010 Antoine DARCHE.
 * @license     http://gnu.org/licenses/gpl.txt GNU GPL
 * @since       PHP 5
 * @version     0.1
 * @package     Hoa_Form
 * @subpackage  Hoa_Form_Element_Other
 */

class Hoa_Form_Element_Other extends Hoa_Form_Element_Abstract {

    /**
     * List of attributes.
     *
     * @var Hoa_Form_Element_Abstract array
     */
    protected $attributes = array();

    /**
     * Value of the textarea.
     *
     * @var Hoa_Form_Element_Textarea string
     */
    protected $value = null;

    /**
     * Built a textarea.
     *
     * @access  public
     * @param   mixed   $attributes    Attributes.
     * @param   mixed   $rest          Rest of options.
     * @return  void
     */
    public function __construct ( $attributes, $rest = array() ) {

        parent::__construct($attributes, 'id');

        if(is_array($rest)) {

            if(isset($rest['value'])) {
                $this->setValue($rest['value']);
            }
            $this->setDecorator('Other');
        }
        else
            $this->setDecorator('Other');
    }

    /**
     * Set the textarea value.
     *
     * @access public
     * @param  string  $value    The textarea value.
     * @return string
     */
    public function setValue ( $value ) {

        $old         = $this->value;
        $this->value = $value;

        return $old;
    }

    /**
     * Get the textarea value.
     *
     * @access  public
     * @return  string
     */
    public function getValue ( ) {

        return $this->value;
    }

    /**
     * Transform the object into a string.
     *
     * @access  public
     * @return  string
     */
    public function __toString ( ) {

        try {

            return $this->getValue();
        }
        catch ( Hoa_Form_Exception $e ) {

            return $e->__toString();
        }
    }
}

3/ Ajouter le décorateur suivant dans Library/Decorator/Other.php

<?php

/**
 * Hoa Framework
 *
 *
 * @license
 *
 * GNU General Public License
 *
 * This file is part of Hoa Open Accessibility.
 * Copyright (c) 2007, 2009 Ivan ENDERLIN. All rights reserved.
 *
 * HOA Open Accessibility is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * HOA Open Accessibility is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with HOA Open Accessibility; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *
 * @category    Framework
 * @package     Hoa_Form
 * @subpackage  Hoa_Form_Decorator_Textarea
 *
 */

/**
 * Hoa_Framework
 */
require_once 'Framework.php';

/**
 * Hoa_Form_Exception
 */
import('Form.Exception');

/**
 * Hoa_Form_Decorator_Abstract
 */
import('Form.Decorator.Abstract');

/**
 * Class Hoa_Form_Element_Textarea.
 *
 * Describe the textarea element.
 *
 * @author      Antoine DARCHE <darche.antoine@gmail.com>
 * @copyright   Copyright (c) 2010 Antoine DARCHE.
 * @license     http://gnu.org/licenses/gpl.txt GNU GPL
 * @since       PHP 5
 * @version     0.1
 * @package     Hoa_Form
 * @subpackage  Hoa_Form_Element_Other
 */

class Hoa_Form_Decorator_Other extends Hoa_Form_Decorator_Abstract {

    /**
     * Make a render of a textarea.
     *
     * @access  public
     * @param   Hoa_Form_Element_Abstract  $element      The element.
     * @param   Hoa_Form_Element_Label     $label        The associated label
     *                                                   element.
     * @param   Hoa_Validate_Abstract      $validator    The element validator
     *                                                   collection.
     * @return  string
     */
    public function render ( Hoa_Form_Element_Abstract $element,
                             Hoa_Form_Element_Label    $label=null,
                             Hoa_Validate_Abstract     $validator ) {

        return $element . "\n";
    }
}

Maintenant l'installation terminé, vous pouvez l'utiliser comme bon vous semble.

exemple simple :

'titrePartOne' = array(
    'type'      => Hoa_Form::ELEMENT_OTHER,
    'value'        => '<br /><br /><h3>Langue du site</h3>'
);

Dernière fois dit par Ecureuil Virtuel (12 May. 2010 22:32)

" L'imagination est plus importante que la connaissance. La connaissance est limitée alors que l'imagination englobe le monde entier, stimule le progrès, suscite l'évolution. " - Life in the cloud :: Getting Started with Hoa - Hoa débutant

2

Re : Hoa_Form_element_Other

Hey smile,

Pas mal.
Vous allez aimer mes brouillons sur Hoa_Form avec XYL.
Au passage, tu as essayé d'utiliser ton code comme Hoathis_Form_Element_Other ?

« Un handicap est le résultat d'une rencontre entre une déficience ou différence et une incapacité de la société à répondre à celle-ci. »

Re : Hoa_Form_element_Other

?? Tu me demande si je l'ai utilisé ? Ou si j'ai testé ce que j'ai donné ??

Car oui je l'utilise et non j'ai pas testé car je venais de le faire à l'instant donc c'était tout frais.
Mais il se peut que je me suis trompé. Merci de remonter les erreurs car j'aurai pas trop le temps aujourd'hui de coder, encore un gros projet en ADA ...

" L'imagination est plus importante que la connaissance. La connaissance est limitée alors que l'imagination englobe le monde entier, stimule le progrès, suscite l'évolution. " - Life in the cloud :: Getting Started with Hoa - Hoa débutant

4

Re : Hoa_Form_element_Other

Je parlais de le faire en tant que module Hoathis wink.

« Un handicap est le résultat d'une rencontre entre une déficience ou différence et une incapacité de la société à répondre à celle-ci. »