Answers.Body: <blockquote>
    <p>My first problem is, I haven't figured out how to properly escape the anchor parameter.</p>
  </blockquote>
  
  <p>I'm guessing you mean the link is being escaped (since Twig will do that by default) and you don't want it to?  If so, you can use the <code>|raw</code> filter (<a href="http://twig.sensiolabs.org/doc/filters/raw.html" rel="nofollow">http://twig.sensiolabs.org/doc/filters/raw.html</a>).</p>
  
  <blockquote>
    <p>My second problem is how to generate a random token. I'd like to generate a random string or something.</p>
  </blockquote>
  
  <p>If you don't care if it's a cryptographically secure string, you can just use <a href="https://craftcms.com/classreference/helpers/StringHelper#randomString-detail" rel="nofollow">StringHelper::randomString()</a> or <a href="https://craftcms.com/classreference/helpers/StringHelper#UUID-detail" rel="nofollow">StringHelper::UUID()</a>.  If you want a cryptographically secure random string, then you can use <a href="http://www.yiiframework.com/doc/api/1.1/CSecurityManager#generateRandomString-detail" rel="nofollow">craft()->security->generateRandomString()</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-08T18:17:53.727Z
Answers.LastActivityDate: 2016-01-08T18:17:53.727Z
Answers.UserDisplayName: Brad Bell
Body: <p>I am (attempting) to and for the most part succeeding in sending an email from a plugin. </p>
  
  <p>My plugin has a textarea in the settings that allows the user to customize the message. The message looks like this by default:</p>
  
  <pre><code>{{ forms.textareaField({
      label:        "Guest Email Message"|t,
      id:           'guestEmailMessage',
      name:         'guestEmailMessage',
      instructions: "The email message."|t,
      value:        (settings.emailMessage ? settings.emailMessage : "&lt;p&gt;Use the link below to complete your request.&lt;p&gt;&lt;a href="{siteUrl}"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Regards,&lt;br&gt;{siteName}&lt;/p&gt;"|t({ siteName: craft.app.siteName })),
      errors:       settings.getErrors('emailMessage')
  }) }}
  </code></pre>
  
  <p>I would like to create something like this:</p>
  
  <pre><code>"&lt;p&gt;Use the link below to complete your request.&lt;p&gt;&lt;a href="http://www.mysite.com/slug/ASDFQWER123"&gt;&lt;/a&gt;&lt;/p&gt;"
  </code></pre>
  
  <p>My first problem is, I haven't figured out how to properly escape the anchor parameter. I've tried single quote and a backslash <code>\</code> (that one). </p>
  
  <p>My second problem is how to generate a random token. I'd like to generate a random string or something. I thought something like <a href="https://craftcms.com/classreference/helpers/UrlHelper#getUrlWithToken-detail" rel="nofollow">getUrlWithToken()</a>, but I'm at the twig level and I'm not sure how that translates.</p>
  
  <p>It would be <em>cool</em> if when I visit the link I am sending I have a way to validate that in my template. Maybe it's a case of if the CSRF token matches? I'm not sure where to start.</p>
  
  <p>Thank you for any suggestions!</p>
  
Tags: <plugin-development><url><emails>
Title: How can I create and validate against a url token?
ThreadText: # How can I create and validate against a url token?
  
  (Asked by: username_0 on 2016-01-08)
  
  I am (attempting) to and for the most part succeeding in sending an email from a plugin.
  
  My plugin has a textarea in the settings that allows the user to customize the message. The message looks like this by default:
  
  ```
  {{ forms.textareaField({
      label:        "Guest Email Message"|t,
      id:           'guestEmailMessage',
      name:         'guestEmailMessage',
      instructions: "The email message."|t,
      value:        (settings.emailMessage ? settings.emailMessage : "<p>Use the link below to complete your request.<p><a href="{siteUrl}"></a></p><p>Regards,<br>{siteName}</p>"|t({ siteName: craft.app.siteName })),
      errors:       settings.getErrors('emailMessage')
  }) }}
  
  ```
  
  I would like to create something like this:
  
  ```
  "<p>Use the link below to complete your request.<p><a href="http://www.mysite.com/slug/ASDFQWER123"></a></p>"
  
  ```
  
  My first problem is, I haven't figured out how to properly escape the anchor parameter. I've tried single quote and a backslash `\` (that one).
  
  My second problem is how to generate a random token. I'd like to generate a random string or something. I thought something like [getUrlWithToken()](https://craftcms.com/classreference/helpers/UrlHelper#getUrlWithToken-detail), but I'm at the twig level and I'm not sure how that translates.
  
  It would be *cool* if when I visit the link I am sending I have a way to validate that in my template. Maybe it's a case of if the CSRF token matches? I'm not sure where to start.
  
  Thank you for any suggestions!
  
  **Tags:** plugin-development, url, emails
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-01-08. Score: 1
  
  > My first problem is, I haven't figured out how to properly escape the anchor parameter.
  
  I'm guessing you mean the link is being escaped (since Twig will do that by default) and you don't want it to? If so, you can use the `|raw` filter (<http://twig.sensiolabs.org/doc/filters/raw.html>).
  
  > My second problem is how to generate a random token. I'd like to generate a random string or something.
  
  If you don't care if it's a cryptographically secure string, you can just use [StringHelper::randomString()](https://craftcms.com/classreference/helpers/StringHelper#randomString-detail) or [StringHelper::UUID()](https://craftcms.com/classreference/helpers/StringHelper#UUID-detail). If you want a cryptographically secure random string, then you can use [craft()->security->generateRandomString()](http://www.yiiframework.com/doc/api/1.1/CSecurityManager#generateRandomString-detail).
  
  
  ---
  
  