You could instantiate the Error Object after the $_POST['go'] is set (the bottom part).
PHP Code:
Class Error
{
var $error = "You must put in a name";
var $good = "good work, name has been entered";
function myError()
{
$pattern = '/[A-Za-z]+/';
if(!empty($_POST['name']) && preg_match($pattern, $_POST['name']))
{
return $this->good;
}
else
{
return $this->error;
}
}
}
PHP Code:
<div>
<?php
if (isset($_POST['go']))
{
$errorCode = new error();
echo $errorCode->myError();
}
?>
</div>
It is Echoing out something cause you have a condition that will either Output $good or $bad.
So you should only echo the object once the Submit $_POST['go'] is placed.
Bookmarks