Forum Topic: Validating Forms Php/javascript

(100 views • 3 replies)

This topic is 1 page long.

<< < > >>
None

64

Reply To Post Reply & Quote

Posted at: 4/13/08 02:08 PM

64 DARK LEVEL 18

Sign-Up: 02/16/04

Posts: 3,870

I've made a basic captcha function that generates a random 5-digit code that the user has to input in order to prove that they are human. Basic stuff. However, I want it to load a javascript function to validate the captcha before the form is funny submitted.

Here's the Javascript:

<script type='text/javascript'>
function check(form){
	if(form.cap.value != <?php echo($c); ?>){
		alert("You must enter the captcha code.");
		form.cap.focus();
		return true;
	} else {
	return true;
	}
}
</script>

The correct captcha string is $c, by the way. Here's my form HTML:

<form name="upf" enctype="multipart/form-data" action=\"\" method="post">

	..Other input shit, blah blah..

	<input name="cap" type="text" maxlength="5"/>
	<input type="submit" value="Upload" name="upload" onclick="return check(document.upf);"/>
</form>

Now, I don't know the least bit of Javascript, at all, so for all I know this could be a very simple problem. I also don't know if the way I'm implementing the PHP variable into the function is correct.

BBS Signature

None

WoogieNoogie

Reply To Post Reply & Quote

Posted at: 4/13/08 02:47 PM

WoogieNoogie LIGHT LEVEL 14

Sign-Up: 06/26/05

Posts: 3,195

You seem to be doing it the correct way...however, without a proper CAPTCHA, bots will read the line of characters and input it into the correct field. I know, it happened to me :(


Sad

64

Reply To Post Reply & Quote

Posted at: 4/13/08 02:51 PM

64 DARK LEVEL 18

Sign-Up: 02/16/04

Posts: 3,870

Well eventually I'll replace it with like, a question or math problem. But that still doesn't help the fact that my code doesn't work.

BBS Signature

None

urbn

Reply To Post Reply & Quote

Posted at: 4/13/08 03:56 PM

urbn FAB LEVEL 16

Sign-Up: 06/10/07

Posts: 1,480

You can do it through PHP easier.

Also, you can use PHP to generate an image with the text on, which simpler bots can't read at all (you need the fuzziness or something similar for near all bots to not read it).

"The world is full of people like you. That's why I try not to go outside" - Me.

BBS Signature

All times are Eastern Daylight Time (GMT -4) | Current Time: 07:32 PM

<< Back

This topic is 1 page long.

<< < > >>
You need a Grounds Gold Account to post on the NG BBS! If you don't have one, click here to sign up now! It's fast, free, and easy — and opens up tons of great NG features!