A little Class Help
Posted: Wed May 25, 2005 9:40 pm
OK, I think its too late because I can't think clearly...
I'm using the following two classes to store HTML form element information.
For instance, say I have a group of check boxes:
box 1:
box label = 'Check Box 1'
box is checked
box 2:
box label = 'Check Box 2'
box is not checked
I'm trying to store the items by doing the following:
However, my output is as follows:
And is what I want is:
I'm using the following two classes to store HTML form element information.
For instance, say I have a group of check boxes:
box 1:
box label = 'Check Box 1'
box is checked
box 2:
box label = 'Check Box 2'
box is not checked
I'm trying to store the items by doing the following:
Code: Select all
$ElementContainer = & new HTML_ElementContainer(HTML_FORM_ELEMENT_CHECK_BOX);
$element1 = &$ElementContainer->addElement();
$element1->setElementLabel('Check Box 1');
$element1->setIsSelected(TRUE);
$element2 = &$ElementContainer->addElement();
$element2->setElementLabel('Check Box 2');
$element2->setIsSelected(FALSE);
echo '<HR><PRE>'; print_r($ElementContainer); echo '</PRE>';
echo '<HR><PRE>'; print_r($element1); echo '</PRE>';Code: Select all
html_elementcontainer Object
(
їlabel] =>
їisSelected] =>
їelementType] => 1
їa_form_elements] => Array
(
ї0] => html_formelements Object
(
їlabel] =>
їisSelected] =>
їelementType] =>
)
)
)
html_formelements Object
(
їlabel] => Check Box 1
їisSelected] => 1
їelementType] =>
)Code: Select all
html_elementcontainer Object
(
їlabel] =>
їisSelected] =>
їelementType] => 1
їa_form_elements] => Array
(
ї0] => html_formelements Object
(
їlabel] => Check Box 1
їisSelected] => 1
їelementType] =>
)
ї2] => html_formelements Object
(
їlabel] => Check Box 2
їisSelected] =>
їelementType] =>
)
)
)Code: Select all
class HTML_FormElements{
var $label = '';
var $isSelected = FALSE;
var $elementType = NULL;
function HTML_FormElements(){
}
function setElementLabel($elementLabel){
$this->label = &$elementLabel;
}
function setIsSelected($isSelected = FALSE){
$this->isSelected = &$isSelected;
}
function setElementType($elementType){
$this->elementType = &$elementType;
}
}
class HTML_ElementContainer extends HTML_FormElements{
var $a_form_elements = array();
function HTML_ElementContainer($elementType){
$this->setElementType($elementType);
}
function addElement(){
$HTMLFEObj = & new HTML_FormElements();
$this->a_form_elements[] = &$HTMLFEObj;
return $HTMLFEObj;
}
}