Sujet : Hoa_Form_element_Other
Il me manquait à chaque fois dans les formulaires pouvoir ajouter du texte entre des champs
Maintenant c'est possible ![]()
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)