January 15th, 2013, 06:08 PM
var nameStr = safe_string(document.getElementById('cf_name').value);
var emailStr = safe_string(document.getElementById('cf_email').value);
var messageStr = safe_string(document.getElementById('cf_message').value);
if(nameStr == "")
document.getElementById('cf_nameCheck').value = "*Enter your name*";
document.getElementById('cf_nameCheck').value = "";
if(emailStr == "" || emailStr.indexOf("@") == -1 || emailStr.indexOf(".") == -1)
document.getElementById('cf_emailCheck').value = "*Enter a valid email*";
document.getElementById('cf_emailCheck').value = "";
if(messageStr == "")
document.getElementById('cf_messageCheck').value = "*Enter your message*";
document.getElementById('cf_messageCheck').value = "";
document.getElementById('cf_name').value = nameStr;
document.getElementById('cf_email').value = emailStr;
document.getElementById('cf_message').value = messageStr;
if(document.getElementById('cf_nameCheck').value == "")
if(document.getElementById('cf_emailCheck').value == "")
if(document.getElementById('cf_messageCheck').value == "")
safe_string is a function that strips out html from input.
All this is fine, but not when I want to check if the captcha is fine, client side.
In the contact submission, using php, this is the end result of the file.
it checks if the given captcha is correct.
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
$mail_status = mail($mail_to, $subject, $body_message, $headers);
Either solution fixes my problem, and I have spent a good 3 days researching and am still no closer.
Any help is greatly appreciated.
January 15th, 2013, 06:51 PM
Make the form support getting default values. As in your PHP looks like
$name = /* value from form, or empty string if not submitted */;
Then if the CAPTCHA check fails you redisplay the form.
<input type="name" value="<?php echo htmlentities($name); ?>" />
January 15th, 2013, 08:50 PM
Does this require the page to be reloaded? Because at the moment, my entire site and all of its 'pages' exist on the index page and a reload defeats the purpose of my design.
Originally Posted by requinix
Originally Posted by requinix
January 15th, 2013, 09:25 PM
Looking at the current code I have...
This line of code can reload the captcha image, and it does not reload the page.
<a href="#" onclick="document.getElementById('captcha').src = '/securimage/securimage_show.php?' + Math.random(); return false">[ Change Code ]</a>
So is there a way that I can call some sort of Php function that returns a true/false that will allow me to do a
when this link is clicked?
document.getElementById.value = "*Invalid*"
<a href ="#!/CheckForm" class="button1" onclick="$(this).closest('form').submit()"onmouseover="" style="cursor: pointer;"><span></span><strong>Send</strong></a>
January 15th, 2013, 09:34 PM
You do an AJAX request with the value the user entered to some PHP script which signals (output, return status code, whatever) whether it's correct or not.
January 15th, 2013, 09:36 PM
Originally Posted by Squigglyo
January 15th, 2013, 11:04 PM
There's nothing wrong with doing validation on the client so long as it's done on the server too. As for CAPTCHA, naturally you wouldn't want to send the correct value to the client in any way, shape, or form... besides the image... but it's fine to send the client's input back to the server as AJAX.
Originally Posted by portcitysoftwar