Exemplo n.º 1
0
 /**
  * Serializes the entire form to XML, all elements included
  *
  * @access     public
  * @param      string	$namespace	Optional namespace to use for the tags
  * @return     string	$xml		The XML representation of the form
  * @see        patForms_Element::toXML()
  * @todo       needs patForms_Element, maybe switch to PEAR::XML_Util
  */
 function toXML($namespace = null)
 {
     $tagName = 'Form';
     // prepend Namespace
     if ($namespace != null) {
         $tagName = $namespace . ':' . $tagName;
     }
     // get all attributes
     $attributes = $this->getAttributes();
     // create valid XML attributes
     foreach ($attributes as $key => $value) {
         $attributes[$key] = strtr($value, $this->xmlEntities);
     }
     $elements = '';
     for ($i = 0; $i < $this->elementCounter; $i++) {
         $elements .= $this->elements[$i]->toXML($namespace);
     }
     return patForms_Element::createTag($tagName, "full", $attributes, $elements);
 }
Exemplo n.º 2
0
 /**
  * [helper method] create an element HTML source from its attribute collection and
  * returns it.
  *
  * @static
  * @access     protected
  * @param      string	$tagname		The name of the element / tag
  * @param      string	$type			Optional: the type of element to generate. Valid parameters are full|opening|closing|empty. Defaults to "full".
  * @param      mixed	$value			The value of the element
  * @return     string	$element		The HTML source of the element
  */
 function createTag($tagname, $type = "full", $attributes = array(), $value = false)
 {
     switch ($type) {
         case "closing":
             return "</{$tagname}>";
             break;
         case "empty":
         case "opening":
             $tag = "<" . $tagname;
             // create attribute collection
             foreach ($attributes as $attributeName => $attributeValue) {
                 $tag = $tag . " " . $attributeName . "=\"" . htmlentities((string) $attributeValue) . "\"";
             }
             // empty tag?
             if ($type == "empty") {
                 $tag = $tag . " />";
                 return $tag;
             }
             $tag = $tag . ">";
             return $tag;
             break;
         case "full":
             if ($value === false) {
                 return patForms_Element::createTag($tagname, "empty", $attributes);
             }
             return patForms_Element::createTag($tagname, "opening", $attributes) . htmlentities($value) . patForms_Element::createTag($tagname, "closing");
             break;
     }
 }