|
Posted by Phil Latio on 03/09/07 22:47
Can anyone tell me why:-
class=\"$this->styleclass\"
statement in the function generateHTML() (which is at very bottom) fails to
pass the value "error" meaning I can't use the style class I defined?
In the example below, I instantiate 3 objects and pass initial arguments to
the constructor. Before displaying the form, I wish to pass a new argument
to one of the objects. I tested it the syntax to ensure the assignment
statement was correct using a simple print statement to confirm it had
updated and indeed it had (this has been commented out below).
Cheers
Phil
<?php
$newform1 = new FormObject("POST", "$PHP_SELF");
$newbox1 = new InputTextBox("first_name", "", "");
$newbox2 = new InputTextBox("last_name", "", "");
$html = "<html><head>";
$html .= "<style type=\"text/css\">";
$html .= ".error";
$html .= "{";
$html .= "color: #781351;";
$html .= "background: #fee3ad;";
$html .= "border: 1px solid #781351";
$html .= "}";
$html .= "</style>";
$html .= "</head><body>";
$html .= $newform1->formOpen();
$html .= $newbox1->generateHTML();
$html .= "<br />";
$html .= $newbox2->generateHTML();
$html .= "<br />";
$html .= $newform1->inputSubmitButton();
$html .= "<br />";
$html .= $newform1->formClose();
$newbox1->setStyleClass("error");
/*
print $newbox1->setStyleClass();
*/
print $html;
class FormObject
{
private $formAction;
private $formMethod;
function __construct($formMethod, $formAction)
{
$this->formMethod = $formMethod;
$this->formAction = $formAction;
}
function formOpen()
{
$html = "<form method=\"$this->formMethod\"
action=\"$this->formAction\">";
return $html;
}
function inputSubmitButton()
{
$html = "<input type=\"submit\" value=\"Submit\" />";
return $html;
}
function formClose()
{
$html = "</form>";
return $html;
}
}
class InputTextBox
{
private $name;
private $styleclass;
private $value;
function __construct($name, $styleclass, $value)
{
$this->name = $name;
$this->styleclass = $styleclass;
$this->value = $value;
}
function setStyleClass($styleclass)
{
$this->styleclass = $styleclass;
}
function getStyleClass()
{
return $this->styleclass;
}
function setValue($value)
{
$this->value = $value;
}
function getValue()
{
return $this->value;
}
function generateHTML()
{
$html = "<input type=text name=\"$this->name\" class=\"$this->styleclass\"
value=\"$this->value\" />";
return $html;
}
}
?>
Navigation:
[Reply to this message]
|