0

Hello to all:

I've been banging my head against the proverbial wall on this (for a few days), and finally thought I'd seek thoughts on it. I have an existing submission form that has been getting hit by bots, so I'm adding a CAPTCHA to it. The entire solution is in 4 files:

  • HTML form
  • PHP file generating 5 alphanumeric code to display as img in HTML
  • AJAX file to control/pass back values
  • PHP file for comparing CAPTCHA challenge and response

    What I'd like to do is have the system submit the form after it confirms the challenge is accepted. I had this implemented in the AJAX when the session is Updated, but it works regardless as to how the user answers the challenge. Any recommendations or nudges in the right direction would be greatly appreciated. I did another instance of this in just html/js, but the CAPTCHA image shows as text and not img, hence not being a viable solution.

2
Contributors
5
Replies
34
Views
2 Years
Discussion Span
Last Post by mattster
0

So what exactly is your problem then? I don't get what isn't working for you.

You could take a look at some big CAPTCHAs, like these:

  1. https://www.phpcaptcha.org/
  2. Are You a Human

Both of these (plus many others) are excellent resources to consider using, and the second one has a plugin for just about any language and lots of major web products.

AJAX can be intergrated fairly easy as well with these two, just create a PHP class as normal to validate the captcha. MAKE SURE that you still validate it post-submission too though!. You'll have to experiment...

0

Thanks. As I said in my post, I'm having trouble having the form submit once the user correctly enters the CAPTCHA answer. I had the submission done in the AJAX, but in testing, I found that it was sending on both correct and incorrect answers. I was then trying to have the validation file execute the submit, but can't find a way to do that in PHP (while JS has syntax for document.getElementById('captchaform').submit(); ). Thanks for the links. I'll go through and get a handle on the logic within. Biggest issue is just getting the whole application to submit the form on correct submission.

0

Okay cool, sounds more like a javascript problem.

Here is another link, to something that appears to do exactly what you want, as a free downloadable tutorial. Here + Demo.

I think the easiest way is to submit the entire form using .post() in jQuery, and check the captcha in a specialist PHP script. If the validation is clear, the jQuery AJAX (that sent the captcha to be checked) then tells the form to submit (or not!).

Hope that makes sense, but it's pretty much what they do in that example. It's tricky javascript, but hopefully you can work from that.

0

Thanks. I'll take a look and get an understanding of what is going on. I'm new to PHP and have gotten a good handle on it from several of the exercises/tutorials online but this was one thing that had me at a loss. If it resolves my questions, I'll mark your post and close this as solved. Thanks for taking the time to reply. I greatly appreciate it.

0

Okay good good, feel free to ask if you need any bit of it explained.

The author is a javascipt coder so his javascript is pretty complicated, but the main lines you might want to change are:

submitRequest.done(function(msg)
                    {
                        //success
                        WEBAPP.cache.$form.submit();
                    });

And maybe the messages to suit your design etc...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.