securimage validation <p>hi everyone i am trying to get validate captcha on my form but i would like validation to take place on the form without a change of state. </p> <p>currently the page refreshes to display the error message and the page loses all form values and i can understand that this can be frustrating to users who have to retype the information.</p> <p>how can i get the error message to display right below the captcha image area? this way the user can make the necessary corrections to their mistake without re-entering everything.</p> <pre><code>&lt;?php session_start(); include_once ("resources/Connections/kite.php"); include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php'; $securimage = new Securimage(); ?&gt; &lt;div class="c13"&gt; &lt;table width="100%" border="0" cellspacing="0" cellpadding="0"&gt; &lt;tr&gt; &lt;td width="69%" align="center"&gt;&lt;p class="c6"&gt;New Account&lt;/p&gt; &lt;?php $username = mysql_real_escape_string($_POST['username']); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string($_POST['password']); $password = mysql_real_escape_string($_POST['password2']); //check if the form has been submitted if(isset($_POST['submit'])){ if ($securimage-&gt;check($_POST['captcha_code']) == false) { // the code was incorrect // you should handle the error so that the form processor doesn't continue // or you can use the following code if there is no validation or you do not know how echo "The security code entered was incorrect.&lt;br /&gt;&lt;br /&gt;"; echo "Please go &lt;a href='javascript:history.go(-1)'&gt;back&lt;/a&gt; and try again."; } else //success echo '&lt;p class="c7"&gt;Thanks for signing up. We have just sent you an email at &lt;b&gt;'.$email.'&lt;/b&gt;. Please click on the confirmation link within this message to complete registration.&lt;br&gt;&lt;img src="resources/img/spacer.gif" alt="" width="1" height="20"&gt;&lt;br&gt;&lt;span class="c12"&gt; &lt;input name="" type="button" class="c11" value="Register" onClick="location.href=\'main.php\'"/&gt; &lt;/span&gt;&lt;br&gt;&lt;img src="resources/img/spacer.gif" alt="" width="1" height="15"&gt;&lt;/p&gt;&lt;/div&gt;'; include_once ("resources/php/footer.php"); exit; } ?&gt; &lt;p class="c7"&gt;Just enter your details to get started&lt;/p&gt; &lt;div class="c10"&gt; &lt;form action="&lt;?php echo $PHP_SELF;?&gt;" method="post" id="register" name="register"&gt; &lt;table width="100%" border="0" cellpadding="0" cellspacing=""&gt; &lt;tr&gt; &lt;td colspan="3" class="c8" height="25px" valign="bottom"&gt;Username&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width="46%"&gt;&lt;/td&gt; &lt;td width="46%"&gt;&lt;/td&gt; &lt;td width="54%" class="c8"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;span id="sprytextfield2"&gt; &lt;input name="username" type="text" class="required"/&gt; &lt;span class="textfieldRequiredMsg"&gt;A value is required.&lt;/span&gt;&lt;span class="textfieldMaxCharsMsg"&gt;Exceeded maximum number of characters.&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8" height="25px" valign="bottom"&gt;Email&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td class="c8"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;span id="sprytextfield3"&gt; &lt;input name="email" type="text" class="required"/&gt; &lt;span class="textfieldRequiredMsg"&gt;A value is required.&lt;/span&gt;&lt;span class="textfieldMaxCharsMsg"&gt;Exceeded maximum number of characters.&lt;/span&gt;&lt;span class="textfieldInvalidFormatMsg"&gt;Invalid format.&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8" height="25px" valign="bottom"&gt;Password (minimum of 8 characters)&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td class="c8"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;span id="sprytextfield4"&gt; &lt;input name="password" type="password" class="required" id="password"/&gt; &lt;span class="textfieldRequiredMsg"&gt;A value is required.&lt;/span&gt;&lt;span class="textfieldMinCharsMsg"&gt;Minimum number of characters not met.&lt;/span&gt;&lt;span class="textfieldMaxCharsMsg"&gt;Exceeded maximum number of characters.&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8" height="25px" valign="bottom"&gt;Confirm Password&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;/td&gt; &lt;td class="c8"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;span id="spryconfirm1"&gt; &lt;input name="password2" type="password" class="required"/&gt; &lt;span class="confirmRequiredMsg"&gt;A value is required.&lt;/span&gt;&lt;span class="confirmInvalidMsg"&gt;The values don't match.&lt;/span&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8" height="25px" valign="bottom"&gt;Enter Code&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;img id="captcha" src="resources/securimage/securimage_show.php" alt="CAPTCHA Image" /&gt;&amp;nbsp; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;input type="text" name="captcha_code" size="10" maxlength="6" /&gt; &lt;a href="#" onclick="document.getElementById('captcha').src = 'resources/securimage/securimage_show.php?' + Math.random(); return false"&gt;Swap image&lt;/a&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;span class="c12"&gt;&lt;img src="resources/img/spacer.gif" width="1" height="40" alt="" /&gt;&lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td colspan="3" class="c8"&gt;&lt;span class="c12"&gt; &lt;input name="submit" type="submit" class="c11" value="Continue"/&gt; &lt;/span&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; &lt;br /&gt;&lt;/td&gt; &lt;td width="31%" valign="middle" align="center"&gt;&amp;nbsp;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; </code></pre>