Access to request headers from validator functions

5 views
Skip to first unread message

Paul Dorman

unread,
Apr 18, 2011, 7:56:47 PM4/18/11
to Sandbar Library
Hi all, I have a simple form that includes a ReCaptcha field. To work
with ReCaptcha, the check function must be passed the remote-addr as
well as the challenge and response. I'm using defform to produce my
form, which is nice and simple, but I'm not sure how to aquire the
remote-address from the request headers in my validation function.
Could someone please describe how I might go about this?

Thanks in advance!

Brenton

unread,
Apr 19, 2011, 12:48:19 AM4/19/11
to Sandbar Library
Paul,

Validators can only validate the data that is submitted with the form.
This means that you will need to submit the remote-addr as a hidden
form field.

Here is how you would do this:

https://gist.github.com/926824

As shown in the code above, the form defaults can be a map or a
function of the request.

In a future version, the field list may also be a function of the
request. I may also consider that for validation.

Brenton

Paul Dorman

unread,
Apr 19, 2011, 1:49:00 AM4/19/11
to sandbar...@googlegroups.com
Thanks for that Brenton, I'll apply it to my code tonight. I'm embarrassed to say that it didn't occur to me at all that defaults needn't be fields!
Reply all
Reply to author
Forward
0 new messages