示例#1
0
 function Serialize()
 {
     $sXml = '<' . $this->sName;
     foreach ($this->aAttrs as $sName => $sValue) {
         if ($sValue === true) {
             $sValue = 'true';
         }
         $sXml .= ' ' . $sName . '="' . VDHtmlEncode($sValue) . '"';
     }
     if (count($this->aSubNodes) > 0) {
         $sXml .= '>';
         foreach ($this->aSubNodes as $sValue) {
             if (is_object($sValue)) {
                 $sXml .= $sValue->Serialize();
             } else {
                 $sXml .= $sValue;
             }
         }
         $sXml .= '</' . $this->sName . '>';
     } else {
         $sXml .= ' />';
     }
     return $sXml;
 }
示例#2
0
 function SetValue($sValue)
 {
     // fix unchecked checkbox populate bug
     if ($sValue === null && $this->bPopulate && in_array($this->sType, array('checkbox', 'radio'))) {
         unset($this->oNode->aAttrs['checked']);
     }
     if ($sValue === null || is_array($sValue)) {
         return false;
     }
     $bResult = true;
     switch ($this->sType) {
         case 'text':
         case 'password':
             if ($this->bPopulate) {
                 if ($sValue != '') {
                     $this->oNode->aAttrs['value'] = VDHtmlEncode($sValue);
                 } else {
                     unset($this->oNode->aAttrs['value']);
                 }
             }
             break;
         case 'hidden':
             if ($this->bPopulate) {
                 $this->oNode->aAttrs['value'] = VDHtmlEncode($sValue);
             }
             break;
         case 'textarea':
             if ($this->bPopulate) {
                 $this->oNode->aSubNodes = array();
                 $this->oNode->aSubNodes[] = VDHtmlEncode($sValue);
             }
             break;
         case 'file':
             $bResult = false;
             break;
         case 'submit':
             if (isset($this->oNode->aAttrs['value'])) {
                 $bResult = $this->oNode->aAttrs['value'] == $sValue;
             } else {
                 $bResult = in_array(strtolower($sValue), array('submit', 'submit query'));
             }
             break;
         case 'image':
             if (isset($this->oNode->aAttrs['value'])) {
                 $bResult = $this->oNode->aAttrs['value'] == $sValue;
             } else {
                 $bResult = false;
             }
             break;
         case 'checkbox':
         case 'radio':
             $sInputValue = isset($this->oNode->aAttrs['value']) ? $this->oNode->aAttrs['value'] : 'on';
             $bResult = $sInputValue == $sValue;
             if ($this->bPopulate) {
                 if ($bResult) {
                     $this->oNode->aAttrs['checked'] = 'true';
                 } else {
                     unset($this->oNode->aAttrs['checked']);
                 }
             }
             break;
         case 'select':
             $bResult = false;
             foreach ($this->oNode->aSubNodes as $nIdx => $mTmp) {
                 $oSubNode =& $this->oNode->aSubNodes[$nIdx];
                 if (is_object($oSubNode) && $oSubNode->sName == 'option') {
                     if ($oSubNode->aAttrs['value'] == $sValue) {
                         $bResult = true;
                         if ($this->bPopulate) {
                             $oSubNode->aAttrs['selected'] = true;
                         }
                     } elseif ($this->bPopulate && !isset($this->oNode->aAttrs['multiple'])) {
                         unset($oSubNode->aAttrs['selected']);
                     }
                 }
             }
             break;
     }
     return $bResult;
 }