Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules

Discuss all other Modules here.

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

TagField module - Adding tags to pages


Reply

3 Posts   1353 Views

Avatar
cm

2 September 2010 at 4:24am Community Member, 7 Posts

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!

Avatar
cm

3 September 2010 at 6:38am Community Member, 7 Posts

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.

Avatar
cm

3 September 2010 at 8:56am Community Member, 7 Posts

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);