Forum Moderators: coopster
I have created a class to control my forms, form validation, post backs, etc using the PHP5 DOM. Ok so my code basically is:
$el = $this->doc->getElementByID($id);
if($el->nodeName == "input") {
$el->setAttribute("value", $value);
}else { //any normal html item
$el->nodeValue = "";
$elString = "<" . $el->nodeName;
$elString2 = "</" . $el->nodeName . ">";
if ($el->hasAttributes()){
foreach ($el->attributes as $attribute){
$elString .= " " . $attribute->name . "='" . $attribute->value ."'";
}
}
$elString .= ">";
$toolbar= new DOMDocument(); //PHP 5 DOM
$toolbar->loadHTML( $elString . $value . $elString2);
//echo $toolbar->saveHTML();
$node = $this->doc->importNode($toolbar->getElementsByTagName($el->nodeName)->item(0),true);
$test = $el->parentNode->replaceChild($node, $el);
} //fi
A bit messy I know, anyway if the nodename is input then I simply ammend the attribute within the node, otherwise I rebuild the entire node (is there a better way of doing this?)
Anyway.
This code works fine on my test machine but the minute I load it up into a live environment it fails to find any nodes which are inputs, it just ignores them, if I change those input fields to textareas then the code works fine. I have read that Input tags are not supported by the php5 DOM, is this so? If so thats a big oversite on their behalf, if not whats wrong with the live server?
Thanks
Have you read any of the user contributed notes for DOM XML Functions [us2.php.net]? You may find your answer there.
Sorry for my poor reponse. Just wanted to give you something :)
if($el->nodeName == "textarea") {), or just the form element types? string DomNode->node_name ( void )Returns name of the node. The name has different meanings for the different types of nodes as illustrated in the following table.
From the manual [us3.php.net]. (Sorry, PHP DOM stuff is pretty new ...)
I suppose I should have been more specific. Im using the PHP5 DOM rather than Dom XML.
The main problem that im having is that Dom XML's function GetElementByID ignores input boxes.
If I create a simple page with an input box with an id of input1 and then do:
$el = $this->doc->getElementByID("input1"); el returns false.
If I change the input box into a textarea $el returns the correct node.