Problem referencing variables in objects



Hello all.

I have an urgent problem building a small form processing system.and hope
somebody out
there can help me?

I have a form class which contains severals elements of the type input text
(created by the
TextInput class). These element classes are added to the $_elements array
that acts as an
object stack (see pseudo code below).

The render() function of the form will loop through the $_elements stack and
calls the render()
functions of each element. This element render() function will return the
html and will finally
build the complete page.

This method workt fine, so I would like to do the same with the validate
function. This also work
as expected, except for one thing:

When the validation of a text input element failes I fill a class variable
called $_message. This
messages should be rendered (displayed) in the "div" element containing the
input text element.
However this is not the case. The message is set and known in the validate()
function but not in
the render() function which is called some time later.

So what am I doing wrong? Is this a problem of the variable scope, or the
wrong way to reference
objects or variables? Can somebody please give me hint?


class Form
{
var $_elements = array();

function render()
{
// render every element in the form $_elements array (return the html
sting)
}

function validate()
{
// call the validate() function of every element in the form $_elements
array
}

}

class TextInput
{
var $_message;

function render()
{
// render this element (return the html sting)
// if a $_message is set (by the validate function) render it into the
html output
}

function validate()
{
// see if the value of this element is valid; if not set the $_message
variable
}
}


.



Relevant Pages

  • Re: Problem referencing variables in objects
    ... I have an urgent problem building a small form processing system.and hope ... The render() function of the form will loop through the $_elements stack ... so I would like to do the same with the validate ... // render this element (return the html sting) ...
    (php.general)
  • Re: Problem referencing variables in objects
    ... I have an urgent problem building a small form processing system.and hope somebody out ... The render() function of the form will loop through the $_elements stack and calls the render ... so I would like to do the same with the validate function. ... // render every element in the form $_elements array (return the html sting) ...
    (php.general)
  • Re: Problem referencing variables in objects
    ... Maybe the TextInput object goes out of scope somewhere between the call to validate and the call to render. ... // render every element in the form $_elements array (return the html sting) ...
    (php.general)
  • Re: Div with borders only partially rendering
    ... add the tidy extension ... and have it validate your html. ... if I load the page, it does not render the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Paypal without HTML email
    ... > Well the reason I suggested Google mail is because it reads HTML without ... the last thing I want is to be able to render it. ... > Actually it's a complete myth that plain text is somehow more secure than ... formatting in its registration process than you've done in discussing ...
    (uk.people.consumers.ebay)