[development] How to interrupt/redirect Search submit to auth/validate (via Captcha) *BEFORE* actual submit to search engine & display of results?

Ben DJ bendj095124367913213465 at gmail.com
Sun May 16 02:00:48 UTC 2010


I've D6 installed.

I'm unwiring my hand-rolled site, and recasting in Drupal.

I'd like to replicate the following logic, but in the most
appropriate, technically valid, "Drupal Way".
(I make that qualification as I'm well aware there are many 'roads' to
any given Drupal 'mountain' ...)

I expose a themed custom Search bar ($search_box) in my theme's top
header/menu bar.

If I enter text into the field, click Submit, the search result's displayed @

	.../search/apachesolr_search/test

I'd like to inject a validation check 'onsubmit', so that

	if USER has not, during this session (anonymous or authenticated)
successfully answered a reCaptcha challenge, then

	BEFORE submitting/returning the search result, redirect the USER to a
standalone Captcha-challenge form, and,

	IF the challenge/response is successful, finish the Search submit
	and return the Search result in the $content region, as usual.

	IF the challenge/response FAILS >#n times, return the user to the home page.

I'd like not reinvent the wheel, and use the existing capabilities of
Drupal core, the Captcha module, etc to the greatest extent possible.

To this end, I,

	installed Capthca module
	installed Webform module
	created a Webform node
	assigned the Captcha module to display @ the Webform node's form_id

cp'd overrides of

	search-theme-form.tpl.php
	webform-form-[nid].tpl.php

to my local theme.

One approach to do what I want, I suppose, is in
search-theme-form.tpl.php, redirect form submission via 'onsubmit=
...' to a "my_captcha_script.php", passing the referrer form_id (here,
'search'), all the various $search $vars, etc -- conditionally
validate the Captcha submit, and then, per conditions above, push the
passed $vars back to a submit form, but with a real 'search' submit
target.

That does not seem Drupal-esque to me.  I'm guessing that the current
best approach is to 'somehow' grab & use FormAPI ...
Finding a method recommendation, and docs to go with it, has beeen a
challenge -- so far.

What's recommended here?

Thanks,

Ben


More information about the development mailing list