[Php-it] [PEAR][QUICKFORM] campo speciale
Marco Sottana
marco.sottana at q-web.it
Mon Dec 11 13:18:40 CET 2006
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]
----- Original Message -----
From: "Marco Sottana" <marco.sottana a q-web.it>
To: <ml a tassoman.com>; "Lista dedicata al linguaggio di programmazione PHP"
<php-it a lists.ziobudda.net>
Sent: Thursday, December 07, 2006 1:48 PM
Subject: [Php-it] [PEAR][QUICKFORM] campo speciale
> ________________SPONSOR______________
> Spazio pubblicitario libero.
> mail a info a ziobudda.net
>
>
>
> ________________SPONSOR______________
>
> 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]
>
>
> _______________________________________________
> Php-it mailing list
> Php-it a lists.ziobudda.net
> Per cancellarsi dalla lista:
> http://lists.ziobudda.net/mailman/listinfo/php-it
>
>
More information about the Php-it
mailing list