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.

Archive /

Our old forums are still available as a read-only archive.

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

Sitewide sitesettings


Go to End
Reply


10 Posts   2570 Views

Avatar
dio5

Community Member, 501 Posts

4 July 2008 at 3:40am

Hi,

to get a better understanding of leftandmain I'm making a module that allows for settings that will be 'sitewide'. Like the SiteTitle and Tagline, which will be settable through the admin from within a different panel and available on the templates through $SiteSettings.Tagline etc...

The module will also allow for 'custom' tags that will be set through a table.
All is going pretty well but I have 2 questions about using a tablefield.

1) Is there an easy way to grab the data from the table when saving - i.e a built in way to do it - or do I just grab the specific information from the $data array manually in my 'save' function?

2) When pressing 'delete' on the table I'm getting an error:

ERROR:Error 256: Form::callfieldmethod() Field 'CustomSettings' not found At l633 in D:\htdocs\ssmymodules\sapphire\forms\Form.php

I think this is about the first argument in my tablefield

$table = new TableField("CustomSettings", "SiteSetting", $tableFields, $fieldTypes,"", $filter);


But what do I need to put there then? - can't seem to get it working yet...

3) One small q:How do I make tabs open by default? - currently when pressing either of the menuitems on the left the tabs on the right stay closed until you really press the tab...

Avatar
Sam

Administrator, 685 Posts

7 July 2008 at 3:12pm

Hi dio5, did you solve this with a custom saver in the end?

Avatar
dio5

Community Member, 501 Posts

7 July 2008 at 7:03pm

Hi Sam,

didn't have the time yet to continue on this.

Gonna try a complex tablefield too , see what that does.

I'll let you know when it's finished :-)

Avatar
dio5

Community Member, 501 Posts

8 July 2008 at 1:12am

Edited: 08/07/2008 1:47am

I tried with a ctf -> same issue/error when 'opening' the popup:

ERROR:Error 256: Form::callfieldmethod() Field 'CustomSettings' not found At l633 in D:\htdocs\ssmymodules\sapphire\forms\Form.php

Now when I changed the 'initial' state/section to 'custom' instead of main, it worked - so I'm starting to think that's the reason of the tablefield not working as well, and perhaps having the tabs not opened initially when clicked in the left panel (so when the right side is ajax-'updated' by clicking on one of the left side items).

It looks like the behaviour isn't applied correctly to the 'new' EditForm.. and I can' t figure out why.. or maybe this is a bug - although in the commentadmin the tabs are opened automatically when clicking through the left side - but there it's always a ctf on the right - while in my case I have 'normal' fields in one section and a tablefield in the other...

The whole problem is solved when my both 'EditForms' are exactly the same - so like in the commentadmin - both ctf's - then the tabs are open and it all works whatever 'section' I have open on init... , although when I want to change the fields depending on which section I'm in - it won't do that because it doesn't retrieve the correct section.

Anyone with ideas?

I can put something on a public domain if that would help :)

Avatar
dio5

Community Member, 501 Posts

8 July 2008 at 8:14am

Edited: 08/07/2008 9:33am

Ok, think I got it working now with a tablefield.

What I needed to do was:

- make sure that all my editforms were the same: so if leftmenuitem "general settings" was with a tablefield, "custom settings" needed to be with a tablefield on rhs as well.
- make a custom save method.

Well here I've lost it completely :-) . What I did works, but I'm not really getting what I'm doing at all:

- I have to do saveInto(singleton('SiteSetting')) to save/edit existing fields
- but manually traverse the data to save 'new' fields

Weird thing: when saving in the 'custom settings' area, it flashes the general settings area for a moment before showing the updated custom settings. UPDATE:: solved by removing 'FormResponse::respond();'

Also: what's the echo getPageFromServer for? - It seems to work only with that...

Anyway, here's the save code - that works (I know it can be arranged a bit better :) ):

function doSave($data, $form)
{
      
   $form->saveInto(singleton("SiteSetting"));
                     
         if(isset($data['SiteSettings']['new']['SettingName']))
         {
            foreach ( $data['SiteSettings']['new']['SettingName'] as $key => $settingname)
            {
               $settingvalue = $data['SiteSettings']['new']['SettingValue'][$key];
               if(empty($settingname) && empty($settingvalue)) continue;
               $setting = new SiteSetting();
               $setting->SettingName = $settingname;
               $setting->SettingSection = "custom";
               $setting->SettingValue = $settingvalue;
               $setting->write();
            }               
            
         }
         echo "$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);";
         echo "statusMessage('Settings Saved.');";
return;
}

More documentation about these areas would be helpful :P

UPDATE: seems that saveInto(singleton("Object")) is enough though... getting confused here :)

Avatar
dio5

Community Member, 501 Posts

8 July 2008 at 8:42am

btw,

if anyone feels like playing with this: here's the first basic version :)

lots of improvements possible :)

Avatar
dio5

Community Member, 501 Posts

8 July 2008 at 8:43am

hmm forgot to upload...

Avatar
dio5

Community Member, 501 Posts

8 July 2008 at 9:41am

Ok, turns out this is enough though:

function doSave($data, $form)
      {
         $form->saveInto(singleton("SiteSetting"));
         echo "$('Form_EditForm').getPageFromServer($('Form_EditForm_ID').value);";
         echo "statusMessage('Settings Saved.', 'good');";   
         return;
      }

The tablefield needs the section through a hiddenfield set with setextradata();
Just wondering if this will be enough to get some sort of validation in?

Go to Top