Answers.Body: <p>You would need to add inputs to the form based on your Tags field handle, with values set to the tag IDs that should be selected.</p>
  
  <p>Here’s a very simple example – it creates a big checkbox list of all the existing tags:</p>
  
  <pre><code>&lt;div id="tags"&gt;
      {% for tag in craft.tags.group('myTagsGroup').limit(null) %}
          &lt;label&gt;
              &lt;input type="checkbox" name="fields[myTagsField][]" value="{{ tag.id }}"&gt;
              {{ tag.name }}
          &lt;/label&gt;
      {% endfor %}
  &lt;/div&gt;
  </code></pre>
  
  <p>Note that it is not possible to create new tags directly from a Tags field. If you want users to also be able to create new tags from your form, that will require a little Javascript.</p>
  
  <pre><code>&lt;a id="new-tag"&gt;+ New tag&lt;/a&gt;
  
  &lt;script type="text/javascript"&gt;
  
      $('#new-tag').click(function()
      {
          var name = prompt('What’s the new tag name?');
  
          if (!name) return;
  
          var data = {
              groupId: 1,
              name: name
          };
  
          $.post('/actions/tags/createTag', data, function(response)
          {
              if (response.success)
              {
                  $('&lt;label&gt;' +
                        '&lt;input type="checkbox" name="fields[myTagsField][]" value="'+response.id+'" checked="checked"/&gt; ' +
                      name +
                    '&lt;/label&gt;').appendTo($('#tags'));
              }
              else
              {
                  alert('Unable to create that tag.');
              }
          });
      });
  
  &lt;/script&gt;
  </code></pre>
  
  <p>Make sure to set the correct <code>groupId</code> in that <code>data</code> object. You can find your tag group’s ID by looking at the URL when editing the group’s settings within Craft’s CP.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-16T22:46:20.207Z
Answers.LastActivityDate: 2014-07-16T22:46:20.207Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I use the following entry form (front-end): <a href="https://craftcms.com/docs/templating/entry-form" rel="nofollow noreferrer">https://craftcms.com/docs/templating/entry-form</a></p>
  
  <p>How can I add a tags-field to this entry form? </p>
  
Tags: <tags><form>
Title: How to add a tags-field to an entry form?
ThreadText: # How to add a tags-field to an entry form?
  
  (Asked by: username_0 on 2014-07-16)
  
  I use the following entry form (front-end): <https://craftcms.com/docs/templating/entry-form>
  
  How can I add a tags-field to this entry form?
  
  **Tags:** tags, form
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-07-16. Score: 4 | Accepted answer
  
  You would need to add inputs to the form based on your Tags field handle, with values set to the tag IDs that should be selected.
  
  Here’s a very simple example – it creates a big checkbox list of all the existing tags:
  
  ```
  <div id="tags">
      {% for tag in craft.tags.group('myTagsGroup').limit(null) %}
          <label>
              <input type="checkbox" name="fields[myTagsField][]" value="{{ tag.id }}">
              {{ tag.name }}
          </label>
      {% endfor %}
  </div>
  
  ```
  
  Note that it is not possible to create new tags directly from a Tags field. If you want users to also be able to create new tags from your form, that will require a little Javascript.
  
  ```
  <a id="new-tag">+ New tag</a>
  
  <script type="text/javascript">
  
      $('#new-tag').click(function()
      {
          var name = prompt('What’s the new tag name?');
  
          if (!name) return;
  
          var data = {
              groupId: 1,
              name: name
          };
  
          $.post('/actions/tags/createTag', data, function(response)
          {
              if (response.success)
              {
                  $('<label>' +
                        '<input type="checkbox" name="fields[myTagsField][]" value="'+response.id+'" checked="checked"/> ' +
                      name +
                    '</label>').appendTo($('#tags'));
              }
              else
              {
                  alert('Unable to create that tag.');
              }
          });
      });
  
  </script>
  
  ```
  
  Make sure to set the correct `groupId` in that `data` object. You can find your tag group’s ID by looking at the URL when editing the group’s settings within Craft’s CP.
  
  
  ---
  
  