Как проверить форму на бэкэнде octobercms

Я расширил октябрьский бэкэнд cms, чтобы в нем было больше мета-полей, и я хочу проверить эти поля, вот как я создал дополнительные поля:

(plugin.php)

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');

               });
}
}

Я прочитал документацию и не понял ее.


person kraven2g    schedule 27.05.2016    source источник
comment
вы изменяете стандартную октябрьскую форму cms? или тот, который вы создали через плагин?   -  person prola    schedule 23.08.2017
comment
Хотите добавить валидацию?   -  person Ashish Detroja    schedule 25.10.2017


Ответы (1)


Я нашел способ привязки к событию проверки страницы в методе плагина boot () следующим образом:

        \CMS\Classes\Page::extend(function($model) {
        $model->bindEvent('model.beforeValidate', function() use ($model) {
            if ($model->url == "/") {
                $model->rules['main_title'] = 'required';
            }
        });
    });
person axima201    schedule 02.11.2017