What im trying to do is load a form and create elements inside it but i end up with something like this:
<form id="form_54" accept-charset="utf-8"></form><input type="text" name="name">
The outpot i'm lookin for is:
<form id="form_54" accept-charset="utf-8"><input type="text" name="name"></form>
this is my function:
public function input($name, $attributes = array(), $type = 'text')
{
$form = new DOMDocument();
$form->loadXML($this->doc->saveHTML());
$input = $form->createElement('input');
$input->setAttribute('type', $type);
$input->setAttribute('name', $name);
if(isset($attributes))
{
foreach($attributes as $attr => $val)
{
$input->setAttribute($attr, $val);
}
}
$form->appendChild($input);
$this->doc->loadXML($form->saveHTML());
}
Correct function thanks to Ghost:
public function input($name, $attributes = array(), $type = 'text')
{
$form = $this->doc->getElementsByTagName('form')->item(0);
$input = $this->doc->createElement('input');
$input->setAttribute('type', $type);
$input->setAttribute('name', $name);
if(isset($attributes))
{
foreach($attributes as $attr => $val)
{
$input->setAttribute($attr, $val);
}
}
$form->appendChild($input);
$this->doc->appendChild($form);
}