search
尋找貓咪~QQ 地點 桃園市桃園區 Taoyuan , Taoyuan

[Laravel]Form – 佛祖球球

Laravel 中的 Form class 可以協助產生前端表單

基本表單使用

{{ Form::open(array('url' => 'foo/bar', 'method' => 'put')) }}


{{ Form::open(array('action' => 'UsersController@index')) }}


{{ Form::open(array('url' => 'foo/bar', 'files' => true)) }}


{{ Form::close() }}

表單內容操作

{{ Form::open(array('url' => 'foo/bar')) }} {{ Form::label('name', 'Name:', array('class' => 'address')) }} {{ Form::text('name', 'Johnson') }} {{ Form::password('password') }} {{ Form::submit('Send this form!') }} {{ Form::close() }}

結合 Model 使用
Controller

class MemberController extends BaseController {
    public function getIndex()
    {
        $member = Member::find('johnsonlu');
        return View::make('home', array('member' => $member));
    }
}

View

{{ Form::model($member, array('url' => array('home/account', $member->nacid))) }}
    {{ Form::label('nacid', 'Account:', array('class' => 'address')) }}
    {{ Form::text('nacid') }}

    {{ Form::label('name', 'Name:', array('class' => 'address')) }}
    {{ Form::text('name') }}

    {{ Form::submit('Send this form!') }}
{{ Form::close() }}

Drop-Down Lists

// Default Select(name, array(value => option_str))
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'));

// Default Select
echo Form::select('size', array('L' => 'Large', 'S' => 'Small'), 'S');

// Range
echo Form::selectRange('number', 10, 20);

// Select Month
echo Form::selectMonth('month');

// Group
echo Form::select('animal', array(
    'Cats' => array('leopard' => 'Leopard'),
    'Dogs' => array('spaniel' => 'Spaniel'),
));

Custom Macros

Form::macro('myInput', function()
{
    return '';
});

echo Form::myInput();
Categories: Laravel



熱門推薦

本文由 blogjohnsonluorg 提供 原文連結

寵物協尋 相信 終究能找到回家的路
寫了7763篇文章,獲得2次喜歡
留言回覆
回覆
精彩推薦