I'm trying to add some very simple PHP CAPTCHA code to my existing HTML web forms, while using my same server side php form mailer.php.

Example form with simple CAPTCHA:
Number challange test<br />
<br />
// check login - only code
if (isset($_REQUEST['submit'])) {
     echo "running code comparison now  ";
    if ($_SESSION['captcha']==$_REQUEST['code']) echo 'login ok';
    else echo 'login failed';
else {
<form action="<? echo $PHP_SELF ?>" method="POST">
Username: <input type="text" name="username" /><br />
Password: <input type="text" name="password" /><br />
<img src="example.php" />
Code: <input type="text" name="code" /><br />
<input type="submit" name="submit" value="Login" />

<? } ?>
Server-side image source:
$captcha = new CaptchaNumbers(4);
$captcha -> display();

$_SESSION['captcha'] = $captcha -> getString();
What is unclear to me, is how can I apply the above value-comparison concept and still submit my form data to my server-side form_mailer.php. Without using submit (to itself) to validate the 'captcha' value to = the 'code'?

I have tried to read/display the value of the $_SESSION['captcha'] (its a 4 digit number) but nothing I do with Echo displays the value. I think if I (could read/display) this value I could validate the code on the fly.

Any guidance appreciated.

This Captcha is from: http://www.phpclasses.org/package/25...on-images.html