[QUICKFORM] array field
| From: | Marco Sottana | Date: | Tue, 12 Dec 2006 08:26:01 +0000 |
| Subject: | [QUICKFORM] array field | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-26075@lists.php.net to get a copy of this message | ||
i correct it ... now it work..
[code]
<?php
require_once('HTML/QuickForm/textarea.php');
class HTML_QuickForm_arrayxot extends HTML_QuickForm_textarea{
/**
* Class constructor
*
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 $this->getValue();
//return serialize(parent::toHtml());
/*
*/
} else {
$html="";
if(strlen( $this->getValue() )>5){
$tmp_arr=unserialize( $this->getValue() );
if(is_array($tmp_arr))
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
//$html.=$nome.'<input type="text" name=\''.$nome.'\'
value=\''.$this->getValue().'\'>';
return $html;
}
}
function getFrozenHtml(){
$nome=$this->getName();
$arr_tmp=array();
//tbl_input_attrs_name[]
$txt="";
$arr_tmp=$this->arraytmp($_REQUEST[$nome."_name"],$_REQUEST[$nome."_value"]);
if($arr_tmp!=array()){
$txt=serialize($arr_tmp);
if(strlen($txt)<25){
$txt="";
}
if($txt=='[a:1:{s:0:"";s:0:"";}]'){
$txt="";
}
}
return $txt;
}
function arraytmp($array_name,$array_value){
$nome=$this->getName();
$arr_tmp=array();
//tbl_input_attrs_name[]
$txt="";
for($ij=0;$ij<count($array_name);$ij++){
$name_tmp=$array_name[$ij];
$value_tmp=$array_value[$ij];
$arr_tmp[$name_tmp]=$value_tmp;
}
return $arr_tmp;
}
//*
function onQuickFormEvent($event, $arg, &$caller)
{
//echo "<hr>event =>
[".$event."][".$arg."][".$caller."]<hr>";
//echo "<pre>";
//print_r($caller->_submitValues);
//echo "</pre>";
$v=$this->getFrozenHtml();
if($v!=""){
//echo "aaaaaaaaaa";
$this->_value=$v;
$this->setValue($v);
}
switch ($event) {
case 'updateValue':
$value = $this->_findValue($caller->_constantValues);
if (null === $value) {
$value = $this->_findValue($caller->_submitValues);
if (null === $value) {
$value = $this->_findValue($caller->_defaultValues);
}
}
if (null !== $value) {
$txt="";
$arr_tmp=($this->arraytmp($caller->_submitValues["attrs_name"],$caller->_submitValues["attrs_value"]));
if($arr_tmp!=array()){
$txt=serialize($arr_tmp);
if(strlen($txt)<25){
$txt="";
}
if($txt=='[a:1:{s:0:"";s:0:"";}]'){
$txt="";
}
}
if($v!=""){
$caller->_submitValues["attrs"]=$v;
//echo "aaaaaaaaaa";
$this->_value=$v;
$this->setValue($v);
}else{
//echo "bbbbbbbbbb";
$this->setValue($value);
}
}
break;
default:
parent::onQuickFormEvent($event, $arg, $caller);
}
return true;
} // end func onQuickFormEvent
}
[/code]