Displaying form

Hi, just have a little problem. I Have my main page, and within a div, I call up a class I created and a method in this class.

<div id="center">
    <?php
    $test= new Form();
    $test->validForm();
   ?>
</div>

In this class, I immediately call the showForm method in the constructor;

function Form(){
		$this->showForm();
    }

The showForm method echo’s out the form I am using. So, this is immediately showed on the page. As you can see from my original class, after the Form class is instantiated, the validForm method comes into play. This method checks if submit was pushed, and if it was, it checks the inputs. After, this comes into play

if (sizeof($this->errorList) > 0){
                $this->showErrors();
                $this->showForm();
            } else {
                $this->sendMail();
            }

So, if the was any errors with the input, it will re show the form. Problem is, the form is being placed below the original form which was showing, instead of replacing it. How can I get it to just replace the original form?

cheers

If I understand your requirement correctly, another option instead of redisplaying the form after any errors could be to get the php method to output javascript that uses a form’s reset() method to reset the form to it’s original values.

Otherwise, when errors occur you could also reload the whole page with the user’s form inputs and the errors highlighted in red.