6

I am having the smart-ip module installed. It allows me to get User country, city etc very easily like this:

echo $_SESSION['smart_ip']['location']['country_code'];

I want to use this as a token replacement in webforms field. But I have no idea how to do it. Got confused after googling. I should do the hooking in template.php? How do i do it? :/

  • 1
    What exactly do you want to do? Use the custom value as a default component value? – Andy Dec 14 '11 at 20:33
6

Create your own tokens!

You could create a small module that implements the token hooks (D6, but D7 should be similar), like so:

function YOURMODULE_token_list($type = 'all') {
  $list = array();

  $list['smart-ip']['smart-ip-country-code'] = t("The Country code");
  // ...etc

  return $list;
}

function YOURMODULE_token_values($type, $object = NULL, $options = array()) {
  $tokens = array();

  $tokens['smart-ip-country-code'] = $_SESSION['smart_ip']['location']['country_code'];
  // ...etc

  return $tokens;
}

Or, even better, add these hooks to the smart_ip.module file and submit a patch to the module maintainer :-). Tokens are really great, and it would certainly be a good addition to the smart_ip module.

-1

install a module called webform_tokens

and what u can do after that is adding your custom token to the module by altering it.

  • This is not correct. Webform Tokens is a helper module for pulling information OUT of webforms, not for putting information INTO Webforms. – Chapabu Dec 15 '11 at 12:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.