Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Dashboard forms error

edited April 2011 in Vanilla 2.0 - 2.8
I've been trying to make a form for a plugin in the dashboard. Tried using the standard template:

For the default.php:
public function SettingsController_tCollapsible_Create(&$Sender) { $Sender->AddSideMenu('plugin/tCollapsible'); $Sender->Form = new Gdn_Form(); $Validation = new Gdn_Validation(); $ConfigurationModel = new Gdn_ConfigurationModel($Validation); $Sender->Form->SetModel($ConfigurationModel); if ($Sender->Form->AuthenticatedPostBack() === FALSE) { $Sender->Form->SetData($ConfigurationModel->Data); } else { $Data = $Sender->Form->FormValues(); $ConfigurationModel->SetField(array_keys($Data)); if ($Sender->Form->Save() !== FALSE) $Sender->StatusMessage = T("Your settings have been saved."); } $Sender->View = dirname(__FILE__).DS.'views'.DS.'dashboard.php'; $Sender->Render(); }

And a normal $this->Form->Open(); inputs, close in the view, nothing fancy at all. Using names like "Plugins.tCollapsible.OPTION_NAME"

I get 2 major errors here:
- whenever I add a new field it won't be saved in the database, dumping C("Plugins.tCollapsible.OPTION_NAME") returns null
- if I apply a rule to the fields in the default.php it works for some reason (I'm guessing something happens in that method that registers the field), but the value isn't displayed in the fields after refresh (remains after callback though) which is extremelly annoying.

I can do it manually by setting the "value" attribute of every field to C("NAME..") but I know there is a better way of doing this, just that I can't seem to see it

Any ideas?

Thanks

Comments

  • Options
    LincLinc Detroit Admin
    edited April 2011
    Use the SaveToConfig function for saving data to the config file. The Model->Save stuff you're using is generally for the database.

    Also might consider using 'TableCollapsible' (or whatever 't' stands for) to follow Vanilla's naming conventions (CamelCase, no abbreviations).
  • Options
    ok, but the most important thing here is: how can I make it so that I have the values I saved from that form appear in the fields next time, and the checkboxes that were selected and save get selected after refresh etc ...
  • Options
    LincLinc Detroit Admin
    edited April 2011
    $Sender->Form->SetFormValue(C('Plugins.Name.Option', $default));
  • Options
    ok, but this is a way of doing this manually. What if you don't know exactly the fields you have and their names (you generate them dynamically).

    Isn't there a way to get the data automatically for all fields according to the inputs for the whole form (like it is done in the normal dashboard forms which I haven't manage to see how exactly do they do that)
  • Options
    LincLinc Detroit Admin
    I'm not really sure what you're asking. Can you explain how you're generating them dynamically?

    Most forms in Vanilla are built to run off a database table, not the config file, which is really just for 1-off values, not lists/tables of data.
  • Options
    so for example I have a plugin that has 3 setup inputs for every application. The way I do that is simply get all applications and generate fields for each and every one of them therefore, if you add new applications later on, new fields will be automatically added to the dashboard view for the plugin therefore the form doesn't have a fixed structure

    Are you saying that for this case I need to have a special table dedicated for that form?
  • Options
    LincLinc Detroit Admin
    Yeah, I'd make a database table for that. Then you'd have one record per application with those 3 values as columns.
Sign In or Register to comment.