[Php-it] [PEAR][QUICKFORM] campo speciale
Marco Sottana
marco.sottana at q-web.it
Thu Dec 7 13:48:02 CET 2006
salve, devo gestire un campo "speciale"..
alla fine devo salvare un array.. e pensavo di salvarlo con serialize
e per visualizzarlo una lista di coppie di campi uno per il nome della
chiave e uno per il valore
questa estensione che ho fatto visualizza in maniera corretta il dato (messo
in precedenza nel db)
e anche il freeze funziona bene (mi mostra esattamente quello che vorrei
salvare nel db..) ma questo dato non mi viene salvato nel db..
se qualcuno puo' aiutarmi...
[code]
<?php
require_once('HTML/QuickForm/textarea.php');
class HTML_QuickForm_arrayxot extends HTML_QuickForm_textarea{
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]
More information about the Php-it
mailing list