Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » TagField module - Adding tags to pages

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1325 Views
  • cm
    Avatar
    Community Member
    7 Posts

    TagField module - Adding tags to pages Link to this post

    Hi,

    I'm having a hard time trying to use this module. What I'd like to do is have a form on a page that let's users add tags to pages. I'm not sure I understand how to implement based on the documentation provided in the readme (I am new to SS, so maybe it'd be more obvious if I had more experience?)

    I have my Tag.php set up:
    class Tag extends DataObject {
       static $db = array(
          'Title' => 'Varchar(255)'
       );
       static $belongs_many_many = array(
          'SomePages' => 'SomePage'
       );
    }

    and SomePage.php:
       static $many_many = array(
          'Tags'=>'Tag'
       );

    I can't seem to have the form work on submit.

    Any help or better documentation?

    Thanks!

  • cm
    Avatar
    Community Member
    7 Posts

    Re: TagField module - Adding tags to pages Link to this post

    Okay, that part is figured out. My new question, if anyone is out there...

    In order to NOT overwrite the existing tags, I need to use: $form->loadDataFrom($this));

    But that's not a great front-end experience, because someone can easily wipe out all the existing tags.

    What's the best way to update the new tags? Is there a way to add the data to that field on form submit? I've been poking around but haven't found anything promising.

  • cm
    Avatar
    Community Member
    7 Posts

    Re: TagField module - Adding tags to pages Link to this post

    Got it.

    So don't use loadDataFrom. In the save function, get the previous tags, loop through and save them in a string. Then, add that string to the new one that comes in from the form.

    Then use:
    $newTags = $form->dataFieldByName('Tags');
    $newTags->setValue($newTagString);

    1325 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.