Page 1 of 1

Creating Dynamic DOM Elements

Posted: Wed Aug 26, 2009 10:05 am
by MikeEller
Hello,

I would like to be able to dynamically create HTML elements (text boxes, labels, buttons, etc) using DOM. Can this be done?
I know that I can create the entire page from scratch using DOMDocument, but I just want to insert elements by creating php objects that implement DOM elements.

For example, if I am in an page, lets say test.php, I want to, in php code, create a textbox. So I need to get a reference to the document (would this be $_SERVER['PHP_SELF']??? and then call createElement('input').

Code: Select all

 
$doc = $_SERVER['PHP_SELF'];
$doc.createElement('input');
 
I want to insert these elements as php objects that create DOM elements.
I need to do this to standardize some things in my environment.

Can anyone point me in the right direction?

Thank You,
Mike

Re: Creating Dynamic DOM Elements

Posted: Wed Aug 26, 2009 11:58 am
by kaszu

Re: Creating Dynamic DOM Elements

Posted: Mon Aug 31, 2009 4:58 pm
by Darhazer
$_SERVER['PHP_SELF'] is not a DomElement.

The PHP itself is not DOM, so unless you do not create a DOMDocument, there won't be any object you can attach an element to.
If you want to create DOM elements in the HTML you've outputting, that you most likely need JavaScript's DOM functions. Otherwise, you can load an HTML in DOMDocument and create the input.