Help with add captcha to a form?

BlueNebula

Junior Member
Joined
Nov 25, 2009
Messages
100
Reaction score
60
Hey guys im running into some problems. Im trying to add this captcha to my form but when I hit the sign up button it just skips the captcha like it isnt even there it is tho.

Here is my form
Code:
<form method="post" action="">
<table cellpadding="0" cellspacing="0" border="0" class="form" style="margin-top: 40px; padding: 50px; border: 1px dotted #ccc;">
<tr><td><label for="username">Username:</label></td><td width="20"></td><td><input type="text" name="user" id="username" size="20" maxlength="25" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="email">Email:</label></td><td width="20"></td><td><input type="text" name="email" id="email" size="20" maxlength="120" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="password">Password:</label></td><td width="20"></td><td><input type="password" name="password" id="password" size="20" maxlength="25" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="password2">Repeat password:</label></td><td width="20"></td><td><input type="password" name="password2" id="password2" size="20" maxlength="25"/></td></tr>
<tr><td><?
$captchaId  = '**** ';   // Set your captcha id here
$publicKey  = '************************************************';   // Set your public key here
echo GetCaptcha($captchaId, $publicKey);
                                ?></td></tr>

<tr><td colspan="2"></td><td><input type="submit" name="register" value="Signup" class="submit" /></td></tr>
</table>  
</form>


Here is what im supposed to add into so it works. Instructions says "On your validation process, place this code:" Which I don't understand?

Code:
$captchaId  = '';   // Set your captcha id here
$privateKey = '';   // Set your private key here
$challengeValue = $_POST['adscaptcha_challenge_field'];
$responseValue  = $_POST['adscaptcha_response_field'];
$remoteAddress  = $_SERVER["REMOTE_ADDR"];

if ("true" == ValidateCaptcha($captchaId, $privateKey, $challengeValue, $responseValue, $remoteAddress))
{
    // Corrent answer, continue with your submission process
} else {
    // Wrong answer, you may display a new AdsCaptcha and add an error message 
}

Any help is much appreciated!
 
I see that your form action is ="", this means that the validation process is within the same file you are making your form.

Code:
<?
require_once('adscaptchalib.php'); // adscaptcha library

$captchaId  = '';   // Set your captcha id here
$privateKey = '';   // Set your private key here
$challengeValue = $_POST['adscaptcha_challenge_field'];
$responseValue  = $_POST['adscaptcha_response_field'];
$remoteAddress  = $_SERVER["REMOTE_ADDR"];

if ("true" == ValidateCaptcha($captchaId, $privateKey, $challengeValue, $responseValue, $remoteAddress))
{
    // Ok, right answer write the information to a database or whatever
	echo 'Registration is successfull';
} else {
    // Wrong answer, you may display a new AdsCaptcha and add an error message 
	echo 'Wrong captcha code, please try again';
}
?>
<form method="post" action="">
<table cellpadding="0" cellspacing="0" border="0" class="form" style="margin-top: 40px; padding: 50px; border: 1px dotted #ccc;">
<tr><td><label for="username">Username:</label></td><td width="20"></td><td><input type="text" name="user" id="username" size="20" maxlength="25" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="email">Email:</label></td><td width="20"></td><td><input type="text" name="email" id="email" size="20" maxlength="120" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="password">Password:</label></td><td width="20"></td><td><input type="password" name="password" id="password" size="20" maxlength="25" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="password2">Repeat password:</label></td><td width="20"></td><td><input type="password" name="password2" id="password2" size="20" maxlength="25"/></td></tr>
<tr><td>
<?
echo GetCaptcha($captchaId, $publicKey);
?>
</td></tr>

<tr><td colspan="2"></td><td><input type="submit" name="register" value="Signup" class="submit" /></td></tr>
</table>  
</form>

Try this, and let me know if it works.
 
As a side note: You should really use CSS to style your form, not a table structure.
 
I see that your form action is ="", this means that the validation process is within the same file you are making your form.

Code:
<?
require_once('adscaptchalib.php'); // adscaptcha library

$captchaId  = '';   // Set your captcha id here
$privateKey = '';   // Set your private key here
$challengeValue = $_POST['adscaptcha_challenge_field'];
$responseValue  = $_POST['adscaptcha_response_field'];
$remoteAddress  = $_SERVER["REMOTE_ADDR"];

if ("true" == ValidateCaptcha($captchaId, $privateKey, $challengeValue, $responseValue, $remoteAddress))
{
    // Ok, right answer write the information to a database or whatever
	echo 'Registration is successfull';
} else {
    // Wrong answer, you may display a new AdsCaptcha and add an error message 
	echo 'Wrong captcha code, please try again';
}
?>
<form method="post" action="">
<table cellpadding="0" cellspacing="0" border="0" class="form" style="margin-top: 40px; padding: 50px; border: 1px dotted #ccc;">
<tr><td><label for="username">Username:</label></td><td width="20"></td><td><input type="text" name="user" id="username" size="20" maxlength="25" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="email">Email:</label></td><td width="20"></td><td><input type="text" name="email" id="email" size="20" maxlength="120" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="password">Password:</label></td><td width="20"></td><td><input type="password" name="password" id="password" size="20" maxlength="25" style="margin-bottom: 10px;"/></td></tr>
<tr><td><label for="password2">Repeat password:</label></td><td width="20"></td><td><input type="password" name="password2" id="password2" size="20" maxlength="25"/></td></tr>
<tr><td>
<?
echo GetCaptcha($captchaId, $publicKey);
?>
</td></tr>

<tr><td colspan="2"></td><td><input type="submit" name="register" value="Signup" class="submit" /></td></tr>
</table>  
</form>

Try this, and let me know if it works.

It didn't work unfortunately. I get this error
Code:
Could not open socket! php_network_getaddresses: getaddrinfo failed: Name or service not known

It also is required to have both these in the form
Code:
$captchaId  = '';   // Set your captcha id here
$publicKey  = '';   // Set your public key here
echo GetCaptcha($captchaId, $publicKey);

and

Code:
$captchaId  = '';   // Set your captcha id here
$privateKey = '';   // Set your private key here
$challengeValue = $_POST['adscaptcha_challenge_field'];
$responseValue  = $_POST['adscaptcha_response_field'];
$remoteAddress  = $_SERVER["REMOTE_ADDR"];

if ("true" == ValidateCaptcha($captchaId, $privateKey, $challengeValue, $responseValue, $remoteAddress))
{
    // Corrent answer, continue with your submission process
} else {
    // Wrong answer, you may display a new AdsCaptcha and add an error message 
}

I've been trying to use this guide. http://www.adscaptcha.com/Resources.aspx
 
It didn't work unfortunately. I get this error

The error:
Code:
Could not open socket! php_network_getaddresses: getaddrinfo failed: Name or service not known

is related to fsockopen, so I guess something is wrong in the libraby you are including.

regarding:

Code:
$captchaId  = '';   // Set your captcha id here
$publicKey  = '';   // Set your public key here

Those are allready stated in the header, so no need to call them again, since you are doing everything in the same file.
 
Back
Top