473,396 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with a $this statement not working

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;
}
}
?>
Mar 9 '07 #1
1 1199
I've just realised that:

$newbox1->setStyleClass("error");

is after

$html .= $newbox1->generateHTML();

so class has no value when the generateHTML is run.

Bugger.

Cheers

Phil
Mar 9 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Dan | last post by:
I was trying to troubleshoot a login page that doesn't work - it keeps saying the login/password is missing - when my tracing discovered this peculiar behavior. register_globals is off, so at...
3
by: Jason Callas | last post by:
I have a stored procedure that runs as a step in a scheduled job. For some reason the job does not seem to finish when ran from the job but does fine when run from a window in SQL Query. I know...
1
by: Alex.Wisnoski | last post by:
I have a data entry form with a combo box to look up an entrant's name. If the name is already in the table then it pulls up the record and that part of the form works fine. If the name isn't in...
3
by: StBond | last post by:
Hi everyone, I am new to Access and Visual Basic so things my be getting across a bit cloudy. I only started using VB for one week. I am having a little problem with the database that I am...
3
by: Andy_Khosravi | last post by:
I have been trying to build a user friendly search engine for a small database I have created. I'm having some particular problems with one of my date fields. Here's the setup: I'm using...
2
by: mob1012 via DBMonster.com | last post by:
Hi All, I wrote last week about a trigger problem I was having. I want a trigger to produce a unique id to be used as a primary key for my table. I used the advice I received, but the trigger is...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
8
by: Ian Mackenzie | last post by:
Hi Guys I am VERY new to DB2 and have created a workingdays function to return the working days between 2 dates, but I get some compiler errors when running it: CREATE FUNCTION WORKINGDAYS...
3
by: das | last post by:
Hi all I am working in Perl from last three months;but using DBI module first time. While accessing Oracle DB through Perl I got a problem given below..... when give SQL statement in mysql it is...
0
by: Filemaxor | last post by:
I have gotten my code to be able to allow people to add new text to a .txt document and able to call up files so the user can see whats in it. The problem i'm having is getting the for loop to work...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.