Form inside TbNavbar Dropdown Items

2019-02-26 09:48发布

I'm trying to add a dropdown login form using Yii Bootstrap, like that attached tutorial, but I'm not able to add HTML Form to TbNavbar items. How can I adapt it?

Followed Tutorial: http://mifsud.me/adding-dropdown-login-form-bootstraps-navbar/

Code:

        <?php $this->widget('bootstrap.widgets.TbNavbar',array(
                'items'=>array(
                    array(
                        'class'=>'bootstrap.widgets.TbMenu',
                        'htmlOptions'=>array('class'=>'pull-right'),
                        'items'=>array(
                            array('label'=>'Login', 'url'=>'#', 'visible'=>Yii::app()->user->isGuest, 'items'=>array(
                                'FORM HTML CODE', // here is the problem, the HTML Form is not working.
                            )),
                        ),
                   ),
            )); ?>

2条回答
forever°为你锁心
2楼-- · 2019-02-26 10:16

Additionally, to keep html markup to a minimum you can also use the 'template' array key:

<?php $this->widget('bootstrap.widgets.TbNavbar',array(
'items'=>array(
    array(
        'class'=>'bootstrap.widgets.TbMenu',
        'htmlOptions'=>array('class'=>'pull-right'),
        'items'=>array(
            array('label'=>'Login', 'url'=>'#', 'visible'=>Yii::app()->user->isGuest, 'items'=>array(
                array(
                    'label'=>'{menu}',
                    'template'=>'<form class="navbar-form pull-left" style="padding-left:15px;padding-right:15px;">
                                    <input type="text" class="span2" placeholder="Login">
                                    <input type="password" class="span2" placeholder="Password">
                                    <button type="submit" class="btn">Submit</button>
                                </form>'
                )
            )),
        ),
    ),
))); ?>

Inside the defined template string you can also use the {menu} placeholder to be replaced with your link.

查看更多
Luminary・发光体
3楼-- · 2019-02-26 10:27

Move your button and form out of the TbMenu items array and into the TbNavbar items array. TbNavBar allows for html but not TbMenu.

    <?php $this->widget('bootstrap.widgets.TbNavbar',array(
            'items'=>array(
                array(
                    'class'=>'bootstrap.widgets.TbMenu',
                    'htmlOptions'=>array('class'=>'pull-right'),
                    'items'=>array(

                    ),
               ),

              '<ul class="nav pull-right">
                   <li><a href="/users/sign_up">Sign Up</a></li>
                   <li class="divider-vertical"></li>
                   <li class="dropdown">
                       <a class="dropdown-toggle" href="#" data-toggle="dropdown">Sign In <strong class="caret"></strong></a>
                       <div class="dropdown-menu" style="padding: 15px; padding-bottom: 0px;">
                          <!-- Login form here -->
                       </div>
                   </li>
               </ul>'
            ),
        )); ?>
查看更多
登录 后发表回答