RSVP validate before submission

I’m trying to implement a different CAPTCHA into the RSVP form, and to do that, I need to validate that the token matches using the Captcha’s API. If it returns a fail, then I would want to stop and show an error message.

I figured I could create a custom application module that would use the onValidatePublicSubmission handler, but I cannot seem to get it to call.

So far, I have created a file named public.application.mtcaptcha.php and have it saved under ./livewhale/client/modules/mtcaptcha/

This is the code inside:

<?php
	$_LW->REGISTERED_APPS['mtcaptcha']=[
		'title'=>'MTCaptcha',
		'handlers'=>['onValidatePublicSubmission']
	]; 

	class LiveWhaleApplicationMtcaptcha {
		public function onValidatePublicSubmission($data_type, $id) {
			global $_LW;

		    error_log("Test, onValidatePublicSubmission function called", 0);

			$_LW->REGISTERED_MESSAGES['failure'][]='TESTING - this is an automatic failure.';
		}
	}
?>

I was hoping that this would just make every from fail and reveal my testing error, but this is not the case. I did add error, hoping to see it in the error log, but that didn’t return any results.
So I tried another handler, just to see if my setup is configured correctly. I added onOutput to my module:

...
	public function onOutput($buffer) {
		global $_LW;

		error_log("Test, onOutput function called");
		return $buffer;
	}
...

This actually added a line to error log, so I feel like the module is somewhat working.

I did play around with changing the name from public to global and private, but they didn’t work either.

Is this the right approach, or am I going in the wrong direction for this type of solution?

Thank you for your time!

Hey Sejr,

Sure thing – onValidatePublicSubmission is only for public submissions, not RSVPs. We’ve added this to the documentation since I think it’s a better match for what you need (it was in core but hadn’t been documented, partly because I don’t think any custom modules have used it before) – onValidatePaymentsForm - LiveWhale Support

I think if you try using that as a model, you can check to see if you’re getting RSVP error messages on dev and from there maybe extend out to use the custom captcha you have in mind.

When you get to this point: I think you’ll want to set PUBLIC_ANSWER and PUBLIC_QUESTION in the core LW config just to meet the out of the box captcha requirement, and then you can use your custom module to do additional captcha/JS stuff on top of that. Hope this helps!

1 Like

This worked beautiful Karl! Thank you

1 Like