How to save widget settings How do you save Widget Settings?

I read this tutorial https://craftcms.com/docs/plugins/widgets several times but I could not find an answer. I'm new to Craft and this is my first plugin.

If I want to save plugin settings I create a Twig template like this

&lt;form method="post" action="" accept-charset="UTF-8"&gt;
        &lt;input type="hidden" name="action" value="sRGoogleAnalytics/settings/saveSettings"&gt;
        &lt;input type="hidden" name="redirect" value="srgoogleanalytics/settings"&gt;
        &lt;input class="btn submit" type="submit" value="{{ 'Submit'|t }}"&gt;
&lt;/form&gt;


and know my function public function actionSaveSettings() in my SRGoogleAnalytics_SettingsController is going to be executed but I don't know how to do the same for widget settings since the widget itself already has a "submit" button and when I create a form in the template there will be two submits.

Could you please explain what I have to do exactly in order to get a callback into a specific function?

Thank you very much
You're over-thinking it a little bit. To save your widget settings, you don't need a controller class, you only need 

a) a method called defineSettings() in your widget class, returning the settings you need, e.g. 

protected function defineSettings()
{
  return array(
    'url'   =&gt; array(AttributeType::Url, 'required' =&gt; true, 'label' =&gt; 'URL'),
    'title' =&gt; array(AttributeType::Name, 'required' =&gt; true),
    'limit' =&gt; array(AttributeType::Number, 'min' =&gt; 0, 'default' =&gt; 5),
  );
}


You can take a look at the AttributeType class to see which attribute types Craft support.

b) a template to render your settings – you don't actually need to create the actual &lt;form&gt; element or add hidden action or redirect inputs in this template; Craft wraps the fields you render inside a form tag. Here's an example settings template corresponding to the settings from the defineSettings() example method above (this is the whole template):

{% import "_includes/forms" as forms %}

{{ forms.textField({
  label: "URL"|t,
  id: 'url',
  name: 'url',
  value: settings.url,
  required: true,
  errors: settings.getErrors('url')
}) }}

{{ forms.textField({
  label: "Title"|t,
  id: 'title',
  name: 'title',
  value: settings.title,
  required: true,
  errors: settings.getErrors('title')
}) }}

{{ forms.textField({
  label: "Limit"|t,
  id: 'limit',
  name: 'limit',
  value: settings.limit,
  size: 2,
  errors: settings.getErrors('limit')
}) }}


Save the template to /yourplugin/templates/widgethandle_settings.html. Finally, you need 

c) a method called getSettingsHtml(), also in your widget class, which simply renders the settings template you added above:

public function getSettingsHtml()
{
    return craft()-&gt;templates-&gt;render('yourplugin/widgettitle_settings', array(
        'settings' =&gt; $this-&gt;getSettings()
    ));
}


With these three things in place, you should be able to click the cogwheel that appears when you mouse over your widget in the Dashboard, which will display your settings form.

To be clear, this is actually exactly the same way plugin settings work, although for plugins themselves the defineSettings() and getSettingsHtml() method should exist in the primary plugin class. In short – you don't need a controller and you don't need the &lt;form&gt; tag, neither for plugin nor widget settings.