How to attach token in a custom form field
token.module has various examples, for example this:

// Add the token tree UI.
$form['email']['token_tree'] = array(
  '#theme' =&gt; 'token_tree_link',
  '#token_types' =&gt; array('user'),
  '#show_restricted' =&gt; TRUE,
  '#weight' =&gt; 90,
);


This displays a link for tokens for the type user (and global tokens).

You can also use the #element_validate callback token_element_validate together with also adding #token_types to have it validated.