How to extend a controller at octobercms?
<p>I want to validate some fields that I have added at the backend by creating a plugin but for that I need to extend the october's controller the controller path is: <code>../modules/cms/controllers/index.php</code> I wanted to add this code to the onSave function that exists inside that controller:</p>

<pre><code>$vars = Input::all();
        $validator = validator::make(
        $vars,
        ['settings[str_seo_title]' =&gt; 'required|alpha',
         'settings[str_local_og_fb_admins]' =&gt; 'numeric'
        ]
      );

      if ($validator-&gt;fails()) {
          flash::error('fields must be properly filled');
        }
</code></pre>

<p>And this is my plugin.php registration file where I have added my extra fields:</p>

<pre><code>public function boot()
    {

      Event::listen('backend.form.extendFields', function($widget)
        { 
  if (!$widget-&gt;model instanceof \Cms\Classes\Page) return;
          //cms page fields
                    $widget-&gt;addFields([
                      'settings[str_seo_title]' =&gt;[
                        'label' =&gt; 'Meta Title',
                        'tab'     =&gt; 'SEO',
                        'type' =&gt; 'text'
                      ],
                      'settings[str_seo_description]' =&gt;[
                        'label' =&gt; 'Meta Description',
                        'tab'     =&gt; 'SEO',
                        'size'    =&gt; 'small',
                        'type' =&gt; 'textarea'
                      ],
                      'settings[str_seo_keywords]' =&gt;[
                        'label' =&gt; 'Meta Keywords',
                        'tab'     =&gt; 'SEO',
                        'type' =&gt; 'text'
                      ],
                      'settings[str_canonical_url]' =&gt; [
                                    'label'   =&gt; 'Canonical URL',
                                    'type'    =&gt; 'text',
                                    'tab'     =&gt; 'SEO',

                                ],
                      'settings[str_robot_index]' =&gt; [
                        'label'   =&gt; 'Robot Index',
                        'type'    =&gt; 'dropdown',
                        'tab'     =&gt; 'SEO',
                        'options' =&gt; ["index"=&gt;"index","noindex"=&gt;"noindex"],
                        'default' =&gt; 'index',
                        'span'    =&gt; 'left'
                      ],
                      'settings[str_robot_follow]' =&gt; [
                        'label'   =&gt; 'Robot Follow',
                        'type'    =&gt; 'dropdown',
                        'tab'     =&gt; 'SEO',
                        'options' =&gt; ["follow"=&gt;"follow","nofollow"=&gt;"nofollow"],
                        'default' =&gt; 'follow',
                        'span'    =&gt; 'right'
                      ],
                      'settings[str_local_og_sitename]' =&gt; [
                        'label'   =&gt; 'Site name',
                        'tab'     =&gt; 'Open Graph',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: strong answer',
                      ],
                      'settings[str_local_og_title]' =&gt; [
                        'label' =&gt; 'Title',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: New features',
                        'tab'   =&gt; 'Open Graph',
                      ],
                      'settings[str_local_og_description]' =&gt; [
                        'label' =&gt; 'Description',
                        'type'  =&gt; 'textarea',
                        'size'  =&gt; 'small',
                        'placeholder' =&gt; 'Example: seo plugin is a plugin that handles meta tags',
                        'tab'   =&gt; 'Open Graph',
                      ],
                      'settings[str_local_og_url]' =&gt; [
                        'label' =&gt; 'Page url',
                        'placeholder' =&gt; 'Example: http://www.strong-answer.com/',
                        'type'  =&gt; 'text',
                        'tab'   =&gt; 'Open Graph',
                      ],
                      'settings[str_local_og_type]' =&gt; [
                        'label' =&gt; 'Type',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: website',
                        'tab'   =&gt; 'Open Graph',
                      ],
                      'settings[str_local_og_author]' =&gt; [
                        'label' =&gt; 'Author',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: Strong Answer',
                        'tab'   =&gt; 'Open Graph',
                      ],
                      'settings[str_local_og_img]' =&gt; [
                        'label' =&gt; 'Image path',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'http://october.com/storage/app/media/Koala.jpg',
                        'tab'   =&gt; 'Open Graph',
                      ],
                      'settings[str_local_og_gl_title]' =&gt; [
                        'label' =&gt; 'Name for the post',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: My post title',
                        'tab'   =&gt; 'Google Tags',
                      ],
                      'settings[str_local_og_gl_description]' =&gt; [
                        'label' =&gt; 'The description of your post',
                        'type'  =&gt; 'textarea',
                        'size'    =&gt; 'small',
                        'placeholder' =&gt; 'Example: seo plugin is a plugin that handles meta tags',
                        'tab'   =&gt; 'Google Tags',

                      ],
                      'settings[str_local_og_gl_img]' =&gt; [
                        'label' =&gt; 'The image of your post',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: http://october.com/storage/app/media/Koala.jpg',
                        'tab'   =&gt; 'Google Tags',
                      ],
                      'settings[str_local_og_gl_page]' =&gt; [
                        'label' =&gt; 'Business page link',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: www.epicsite.com',
                        'tab'   =&gt; 'Google Tags',
                      ],
                      'settings[str_local_og_tt_card]' =&gt; [
                        'label' =&gt; 'Summary of your card',
                        'type'  =&gt; 'textarea',
                        'size'  =&gt;  'small',
                        'placeholder' =&gt; 'Example: Happy 3rd anniversary #TBT!',
                        'tab'   =&gt; 'Twitter Tags',
                      ],
                      'settings[str_local_og_tt_site]' =&gt; [
                        'label' =&gt; 'Twitter user',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: @stronganswer',
                        'tab'   =&gt; 'Twitter Tags',
                      ],
                      'settings[str_local_og_tt_title]' =&gt; [
                        'label' =&gt; 'Twitter title',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: Small Island Developing States Photo Submission',
                        'tab'   =&gt; 'Twitter Tags',
                      ],
                      'settings[str_local_og_tt_description]' =&gt; [
                        'label' =&gt; 'Twitter description',
                        'type'  =&gt; 'textarea',
                        'size'  =&gt; 'small',
                        'placeholder' =&gt; 'Example: seo plugin is a plugin that handles meta tags',
                        'tab'   =&gt; 'Twitter Tags',
                      ],
                      'settings[str_local_og_tt_img]' =&gt; [
                        'label' =&gt; 'Twitter image',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: http://october.com/storage/app/media/Koala.jpg',
                        'tab'   =&gt; 'Twitter Tags',
                      ],
                      'settings[str_local_og_fb_appid]' =&gt; [
                        'label' =&gt; 'Facebook App Id',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: 302184056577324',
                        'tab'   =&gt; 'Facebook Tags',
                      ],
                      'settings[str_local_og_fb_admins]' =&gt; [
                        'label' =&gt; 'Facebook Admins',
                        'type'  =&gt; 'text',
                        'placeholder' =&gt; 'Example: 1234,2314',
                        'tab'   =&gt; 'Facebook Tags',
                      ]
          ],  'primary');



               });
</code></pre>