Activeform Beforesubmit

Hello-

Can someone explain why ActiveForm validation is required for beforeSubmit to fire.

Path: vendor/yiisoft/yii2/widgets/ActiveForm.php

Line: 180


    /**

     * Runs the widget.

     * This registers the necessary javascript code and renders the form close tag.

     */

    public function run()

    {

        if (!empty($this->attributes)) { /* << Why is this necessary */

            $id = $this->options['id'];

            $options = Json::encode($this->getClientOptions());

            $attributes = Json::encode($this->attributes);

            $view = $this->getView();

            ActiveFormAsset::register($view);

            $view->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);");

        }

        echo Html::endForm();

    }




When I comment out the line requiring attributes it works without error for me.

Though I am not suggesting this is a solution.

Any insight is appreciated.

This seems to work.


<?php $form = ActiveForm::begin([

        'id'           => 'demo-form',

        'options'      => [ 'class' => 'form-horizontal' ],

        'attributes' => $model->attributes(), /* << Here */

        'beforeSubmit' => 'my_function',

    ]

); ?>