使用“标签"小部件将ActiveForm字段拆分为不同的标签 [英] Split ActiveForm fields into different tabs with Tabs widget

查看:145
本文介绍了使用“标签"小部件将ActiveForm字段拆分为不同的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个表单视图,我想使用正式的Tabs小部件来组织具有Tabs结构的表单字段.

I'm creating a form view and I want to organize the form fields with tabs structure, using the official Tabs widget.

是否可以使用包含活动表单字段的div元素的ID(或类)来初始化Tabs小部件?

Is it possible init the Tabs widget with the id (or class) of the div elements that contains the active form fields?

推荐答案

如何管理它的一个示例是这样的:

One example of how you can manage it is doing like this:

  1. 首先,将您的联系表单分为每个选项卡一个视图文件.
  2. 将ActiveForm :: begin()和ActiveForm :: end()放在Tabs :: widget()周围
  3. 使用参数$ model和$ form将联系表单页面呈现为内容

示例代码:

views/site/contact.php

<?php

/* @var $this yii\web\View */
$this->title = 'Contact';

use yii\bootstrap\Tabs;
use yii\bootstrap\ActiveForm;
?>


<?php $form = ActiveForm::begin(['id' => 'contact-form']); ?>
<?= Tabs::widget([
        'items' => [
            [
                'label' => 'One',
                'content' => $this->render('contact_form1', ['model' => $model, 'form' => $form]),
                'active' => true
            ],
            [
                'label' => 'Two',
                'content' => $this->render('contact_form2', ['model' => $model, 'form' => $form]),
            ],
        ]]);
 ?>
    <?php ActiveForm::end(); ?>

views/site/contact_form1.php

<?= $form->field($model, 'name') ?>
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'subject') ?>

views/site/contact_form2.php

<?php
use yii\helpers\Html;
use yii\captcha\Captcha;
?>

<?= $form->field($model, 'body')->textArea(['rows' => 6]) ?>
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
    'template' => '<div class="row"><div class="col-lg-3">{image}</div><div    class="col-lg-6">{input}</div></div>',
]) ?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary', 'name' => 'contact-button']) ?>
</div>

希望这会有所帮助!

这篇关于使用“标签"小部件将ActiveForm字段拆分为不同的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆