Hello,
I am trying to make my own form handler.
This is a part of my code in my form class.
if ($attrib['elements'])
{
$this->elements = $attrib['elements'];
$this->field = new PHP_Myelement($this->elements);
$this->field->runElements();
if (method_exists($this->field))
{
throw new Exception("Method does not exist");
}
}
if (empty($this->elements))
{
throw new Exception("Set form elements");
}
I want to get the $this->elements array in my element class.
With the following code.
class Element
{
public function __contruct($elements=null)
{
if (is_array($elements))
{
$this->setElements($elements);
}
if (empty($this->elements))
{
throw new Exception("Set form elements");
}
}
//Set form elements
public function setElements($elements=array())
{
if ($elements['username'])
{
$this->element = $elements['username'];
$this->elementOptions($this->element);
}
if (empty($this->element))
{
throw new Exception("No element ".$this->element."");
}
}
public function elementOptions($element=array())
{
if ($element['type'])
{
$this->type = $element['type'];
}
if (empty($this->type))
{
throw new Exception("No type");
}
}
public function runElements()
{
$this->form = "".$this->type."";
}
public function __toString()
{
return $this->form;
}
}
Can someone tell me why my code isn't output the $this->form? It works when I use a simple string. And how can I debug this code. Because, the Exception code doesn't work in my element class.
Thanks in advance.