Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

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

I want to change this:

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

to something like this:

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

I know that the second option isn't correct, anyone knows how to write it in a correct way?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...