I am trying to create my own settings form (EE5) using the documentation, but when i am using the function settings_form() & save_settings() and calling the "return ee('View')->make('my_extension:index')->render($vars);" it will not save. It displays correctly and submits the form but doesn't save. When I run the settings() function it works fine, but I need to create some custom areas. Anyone experiencing similar issues with it not saving.

  • When using custom settings methods, you need to perform the save routine yourself within save_settings(). Are you manually saving your extension settings in that method? – Derek Hogue Dec 3 at 13:43
  • I am not saving them manually. I was under the impression that when the save_settings() method is called it will submit the form data automatically to the /save. I watched the data and both save_settings() and settings() are submitting the same parameters but one is saving and the other isn't. How do I save the settings manually? – James Raffield Dec 3 at 15:27
up vote 0 down vote accepted

The save_settings() method doesn't do anything with your settings data simply by existing - you need to process the submission yourself. From the docs:

Use it to process the data sent and put it into the exp_extensions database table. Remember that the data put into the database is a serialized array, so handle it appropriately.

The easiest way to do this is using the existing Extension model, which abstracts a lot of that work for you:

$model = ee('Model')->get('Extension')
    ->filter('class', ucfirst(get_class($this)))
    ->first();

$my_settings = array(
    'foo' => ee('Request')->post('foo'),
    'bar' => ee('Request')->post('bar')
);

$model->settings = $my_settings;
$model->save();

(Since the settings property of the Extension model is set to be serialized data, you only have to assign an array to it - the serialization will happen in the model.)

  • Thank you very much. Derek you answer was spot on! – James Raffield Dec 4 at 19:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.