[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 18:22:36 UTC 2010


Hi Lee,

Thanks for the reply!

On Sun, May 16, 2010 at 1:36 AM, Lee Rowlands
<leerowlands at rowlands-bcs.com> wrote:
> That said you should have a look at hook_form_alter
... (snip) ...
> Hope this makes sense.

It's helped me make some progress, tho I'm not sure I've managed to
implement your suggestion (correctly) ...

So far:

I've created a webform (form_id == 'webform_client_form_8', pathalias
== test/mycaptcha).

I've added form_id == 'webform_client_form_8' as a target for the
Captcha module.

I've created a custom.module:

-----------------------------------------------------
function custom_form_alter(&$form, $form_state, $form_id) {
	switch ($form_id) {
		case 'search_theme_form':
			if(isset($_SESSION['captcha_success_form_ids'])) {
				$form['#redirect'] = 'search';
			} else {
				$form['#redirect'] = 'test/mycaptcha';
			}
			break;
		case 'webform_client_form_8':
			// ...
			break;
	}
}
-----------------------------------------------------

This now works as follows ...

@ enter text into my search bar, and Submit, then

(1) if there's been NO prior, valid captcha auth, & hence no SESSION
var set, then I redirect to my standalone, captcha-containing webform.

(2) if there HAS been valid auth, simply redirect to the search as
usual.  and, the search result page is properly displayed.

both good.

the remaining issue is, if I'm in case (1), above, and have redirected
to the captcha-containing webform, AND sucessfully submitted the
captcha,  NOW i want to "continue on" to the search submit, with the
originally submitted search parameters.

since the 'successful' captcha SESSION var will have been set, there's
no concern of looping backto the standalone captcha page ...

but how should I be storing/passing the originally submitted search
params BACK to the 'new' search?  afaict, looking in
/src/www/mysite/modules/search/ there's no mention/reference of a
_SESSION var there, so I'm guessing either i have to (a) manually
store/pass the search params in my own SESSION var, *or* they're
already stored in a Drupal core var.

reading our post again, i'm not at all sure if i _should_ have used,

     array_unshift($form['#submit'], 'name_of_your_handler');

tbh, i'm not clear abt it's intent, or proper use -- yet.


Thanks!

Ben


More information about the development mailing list