Dashboard forms error
I've been trying to make a form for a plugin in the dashboard. Tried using the standard template:
For the default.php:
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
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
1
Comments
Also might consider using 'TableCollapsible' (or whatever 't' stands for) to follow Vanilla's naming conventions (CamelCase, no abbreviations).
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)
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.
Are you saying that for this case I need to have a special table dedicated for that form?