special filed QuickForm
| From: | Marco Sottana | Date: | Thu, 07 Dec 2006 11:55:01 +0000 |
| Subject: | special filed QuickForm | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26005@lists.php.net to get a copy of this message | ||
i need to handle a special field ..
in database record is a TEXT
my field must save "serialize($array)"
and this filed must shown as a list of "input text" one for the "key" and one for the "value"
this code... read and show where i want to do.. but i can't save.. anyone can help me? please..
[code]
<?php
require_once('HTML/QuickForm/textarea.php');
class HTML_QuickForm_arrayxot extends HTML_QuickForm_textarea{
/**
* Class constructor
*
* @param string Htmlarea name/id
* @param string Htmlarea label
* @param array Options for htmlarea
* @param string Attributes for the textarea
* @access public
* @return void
*/
function HTML_QuickForm_arrayxot($elementName=null, $elementLabel=null, $options=array(), $attributes=null)
{
HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
$this->_persistantFreeze = true;
$this->_type = 'arrayxot';
if (is_array($options)) {
foreach ($options as $k => $v) {
if (isset($this->{"_$k"}) && method_exists($this, "set$k")) {
$this->{"set$k"}($v);
}
}
}
}
function toHtml(){
$nome=$this->getName();
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
//return serialize(parent::toHtml());
/*
*/
} else {
$html="";
if(strlen( $this->getValue() )>5){
$tmp_arr=unserialize( $this->getValue() );while (list($key, $value) = each ($tmp_arr)) {
//echo "Chiave: $key; Valore: $value<br>\n";
$html.= '<input type="text" name="'.$nome.'_name[]" value="'.$key.'">'." => ".'<input type="text" name="'.$nome.'_value[]" value="'.$value.'"><br>';
}//end while
}//end if
for($iij=0;$iij<3;$iij++){
$html.= '<input type="text" name="'.$nome.'_name[]" value="">'." => ".'<input type="text" name="'.$nome.'_value[]" value=""><br>';
}//end for
return $html;
}
}
function getFrozenHtml(){
$nome=$this->getName();$arr_tmp=array();
//tbl_input_attrs_name[]
for($ij=0;$ij<count($_REQUEST[$nome."_name"]);$ij++){
$name_tmp=$_REQUEST[$nome."_name"][$ij];
$value_tmp=$_REQUEST[$nome."_value"][$ij];
$arr_tmp[$name_tmp]=$value_tmp;
}
if($arr_tmp!=array()){
$txt=serialize($arr_tmp);
if(strlen($txt)<25){
$txt="";
}
if($txt=='[a:1:{s:0:"";s:0:"";}]'){
$txt="";
}
}
return $txt;
}
}
[/code]