Form inside TbNavbar Dropdown Items

后端 未结 2 375
死守一世寂寞
死守一世寂寞 2021-01-22 05:12

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 ca

相关标签:
2条回答
  • 2021-01-22 06:02

    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>'
                ),
            )); ?>
    
    0 讨论(0)
  • 2021-01-22 06:06

    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.

    0 讨论(0)
提交回复
热议问题