简体   繁体   English

如何提交yii 2表单加载

[英]How to submit yii 2 form onload

Pjax::begin();
$form = ActiveForm::begin();
echo $form->field($model, 'testdata', [
                  'inputOptions' => [
                  'class' => 'form-control input-xsmall input-inline' ],
                  ])->label(Yii::t('app', 'Records : '))
                  ->dropDownList(['10'=> 10, '15' => 15, '20' => 20, '50' => 50], ['onchange'=>"this.form.submit();"]);

ActiveForm::end();
Pjax::end();

The form above allows me to submit form on change event. 上面的表格允许我在变更事件时提交表格。
How can I make the form submit onload? 如何使表单在​​加载时提交?

You can use onloadFunctions as shown below. 您可以使用onloadFunctions ,如下所示。 You need to define the property inside your controller. 您需要在控制器内部定义属性。 Source 资源

<body onload="<?php echo Yii::app()->controller->onloadFunction; ?">

Controller : 控制器:

class MyController extends Controller
{
     public $onloadFunction='AJavascriptFunction();';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM