[consulting] how to create token and use them in form text area

Sam Tresler sam at treslerdesigns.com
Thu Jun 17 18:21:14 UTC 2010


Are you making your own form?

If so, just run the text in question through token_replace($text, 'global', $object); in the form_submit function.  I believe those are all default tokens so I don't think you need an $object, but you might need to pass the $user object.  I'm not sure.  Also, 'global' may need to be 'user' depending on your use case.

   You don't need to use token_get_list unless you need to modify the replacement text that you get back from token_replace().

Regards,
   Sam

On Thu, 17 Jun 2010, sidharth relhan wrote:

> In my problem i have to store few variable as token like user name and user
> id and use these variable in email body. Here email body is customize in
> text area and saved as set variable. That is the reason i cant use token
> filter.
> I try to print
>
> [user-name]
> [user-id]
> [user-mail]
> [site-url]
> [site-name]
> these global variable thew can't show appropriate result
> i use this function to get these variable
> print_r(token_get_list($types = 'all'));
>
>
>
> On Thu, Jun 17, 2010 at 10:39 PM, Travis Carden <travis.carden at gmail.com>wrote:
>
>> You aren't just asking how to display a token in a node body, are you?
>> Because if that's all you want, you can just use Token Filter<http://drupal.org/project/token_filter>module.
>>
>>
>> On Thu, Jun 17, 2010 at 10:31 AM, Bhavin Joshi <bhavinjosi at joshics.in>wrote:
>>
>>> You can create your own token but you have to write a function or few
>>> lines of code to replace them with the original values.
>>> Like, you have to replace the values using t(<string>, array(tokens));
>>> I use the same technique in some of my contributed modules.
>>>
>>> Regards.
>>>
>>> 2010/6/17 sidharth relhan <sidhartharelhan at gmail.com>
>>>>
>>>> Hello!!
>>>> I stuck with a problem in creating and using token.
>>>> I think that it is create using function hook_token_value()
>>>> and using token_replace() function it replace variable but how to use
>>> token in the body
>>>> Example of creating token
>>>>
>>>> As in view they are called like [user].
>>>> How to call them in the normal body if they are defined global.
>>>> _______________________________________________
>>>> consulting mailing list
>>>> consulting at drupal.org
>>>> http://lists.drupal.org/mailman/listinfo/consulting
>>>>
>>>
>>>
>>>
>>> --
>>> Bhavin H. Joshi
>>> Mobile: +91 999 886 0979
>>> Skype: bhavinjoshi19
>>> google: bhavinjosi at joshics.in
>>> Web: http://joshics.in
>>> Get your tiny URL: http://ly2.in
>>> Portfolio: http://sites.google.com/site/bhavinhjoshi/portfolio
>>> _______________________________________________
>>> consulting mailing list
>>> consulting at drupal.org
>>> http://lists.drupal.org/mailman/listinfo/consulting
>>>
>>
>>
>> _______________________________________________
>> consulting mailing list
>> consulting at drupal.org
>> http://lists.drupal.org/mailman/listinfo/consulting
>>
>>
>

Sam Tresler
646-246-8403



More information about the consulting mailing list