I tried both of the above captcha code tutorials and neither one worked with my UsersController. I was able to register every time that I typed in the wrong captcha code. This is from my registration method in my UsersController:
I tried to make a validation rule in my Users table, but it didn’t work. Maybe I have to create the fields in the database for it to work but I’m not sure which fields I should use.
$validator -> sameAs('theCaptcha','recaptcha','Captcha is false');
I tried to adapt the CakePHP submit button to match the javascript captcha button as follows:
Sorry, I’m not clear. You’ve created two Register buttons in your form?
When your validation rule fails to generate an error, what does the user entity look like? In particular, what’s in the theCaptcha and recaptcha fields? And how did anything get into that entity, when you apparently haven’t patched your form data into it?
Thanks for your feedback, Zuluru. I was showing the codes I used for each of the tutorials. One code per tutorial not 2 buttons.
I wrote the validation rule without creating fields in the table because I don’t know exactly which variable from the given code to use as fields.
You shouldn’t need for there to be fields in the database for this. You will need for the entity to accept the data. You haven’t addressed the question about how that’s happening, or what the entity looks like when you try to save it.
I googled cakephp entity and got this website: Class Entity | CakePHP 4.0 but it didn’t help. Can you recommend a more simple tutorial about cakephp entities?
The form was only using classes and the text input fields had empty names so I added a couple of text boxes with the names captchaText_ and captchaInputBox_ as follows:
I editted the validators and the accessible property to reflect the new names with underscores. It’s now working but the error message “Entered captcha is not correct” shows up for just a split second and then disappears.