msgsys class include file:
PHP Code:
class msgsys { var $message; function addmsg($msg) { $message .= $msg; echo $message; } function showmsg() { echo $message; } }
formchk class include code:
PHP Code:
class formchk { var $highlight = array(); function validchk($regval, $fieldval, $msg) { if ( !preg_match($regval, $fieldval) ) { msgsys::addmsg($msg); } } function getregex() { foreach ($_POST as $field => $value) { switch ($field) { case "fname": $regval = "/^[a-zA-Z\s]{2,}$/"; $msg = '<font size="2" color="#FF0000">First name must only contain alpha(a-z) characters.</font><br><br>'; $this->validchk($regval, $value, $msg); break; } } } }
addaccount file code:
PHP Code:
<?PHP if ( $_POST['submit'] == "Add" ) { include ('msgsys_cls.php'); include ('formchk_cls.php'); $srtmsg = new msgsys; $srtchk = new formchk; $srtchk->getregex(); } ?> <form action = "" method="post"> <table border="1" width="550px"> <tr> <td colspan="2"> <?php if ( $_POST['submit'] == "Add" ) { echo 'Echoing out the messege!'; $srtmsg->showmsg(); } ?> </td>
To start off, when the add buttom is clicked my both classes are being instantiating next, getregex() function from the formchk class is executed. Within that function, I'm passing a message over to the msgsys class by executing this syntax: msgsys::addmsg($msg); Since I'm using scope (:  I don't need to use $this-> (reason being I'm not instantiating this class) inside the addmsg function in the msgsys class. To double check that, I used $this-> and my script didnt work correctly, when I didn't use $this-> the script semi worked.
The problem I'm running into is this with: <?php if ( $_POST['submit'] == "Add" ) { echo 'Echoing out the messege!'; $srtmsg->showmsg(); } ?> which is in the addaccount page. $startmsg->showmsg(); is not outputting my message variable. I'm not sure If the variable is losing it's value or what?
Can anyone give me a hand with this?
-Thanks
|