0

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: ../modules/cms/controllers/index.php I wanted to add this code to the onSave function that exists inside that controller:

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

      if ($validator->fails()) {
          flash::error('fields must be properly filled');
        }

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

public function boot()
    {

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

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

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



               });
kraven2g
  • 167
  • 1
  • 16

0 Answers0