Is it possible to put a bootstrap glyphicon inside of a {{ Form::submit(' ')}} - Laravel

后端 未结 4 1094
悲&欢浪女
悲&欢浪女 2020-12-14 08:40

I want to change this:

{{ Form::submit(\'Delete this User\', array(\'class\' => \'btn btn-warning\')) }}

to something like this:

<
相关标签:
4条回答
  • 2020-12-14 08:46

    Use a <button> of type submit, which adds more flexibility then a submit input:

    {{Form::button('<i class="glyphicon glyphicon-delete"></i>', array('type' => 'submit', 'class' => ''))}}
    

    To make it clear, this is the class method:

    public function button($value = null, $options = array())
    {
       if ( ! array_key_exists('type', $options) )
       {
           $options['type'] = 'button';
       }
    
        return '<button'.$this->html->attributes($options).'>'.$value.'</button>';
    }
    

    As you can see, $value holds anything you put inside the <button> tag, so placing the icon there should work - I use this with Fontawesome icons and it works fine, I personally tend to use those instead of Glyphicon but the principle remains the same.

    By using Form::submit(), instead, you create an <input type="submit" which cannot accept html as content of the value attribute, that's why your solution won't work.

    0 讨论(0)
  • 2020-12-14 08:46

    I used Html::linkRoutes to create a button and cannot implement the methods you guys mentioned before... Any one have any guesses? Heres my code:

    <div class="col-md-12">
              {{ Html::linkRoute('posts.index', '<< Back to blog', [], ['class' => 'btn2 btn2-default']) }}
    </div>
    
    0 讨论(0)
  • 2020-12-14 08:59

    You can add your icon class to your class array like:

    array('class' => 'btn btn-primary glyphicon glyphicon-remove');
    
    0 讨论(0)
  • 2020-12-14 09:05

    This works for me

    {{ Form::button('<span class="glyphicon glyphicon-remove"></span>', array('class'=>'btn btn-default', 'type'=>'submit')) }}
    
    0 讨论(0)
提交回复
热议问题