laravel架構中註冊資訊驗證

來源:互聯網
上載者:User

標籤:

1.路由配置
<?php
Route::get(‘/‘,[‘as‘=>‘blog.index‘,‘uses‘=>‘[email protected]‘]);
Route::get(‘/create‘,[‘as‘=>‘blog.create‘,‘uses‘=>‘[email protected]‘]);
Route::post(‘blog/store‘,[‘as‘=>‘blog.store‘,‘uses‘=>‘[email protected]‘]);
 2. 控制器分配頁面及驗證表單提交內容
<?php
class BlogController extends \BaseController {
    /**
     * Display a listing of the resource.
     *
     * @return Response
     
*/
    public function index()
    {
        return View::make(‘blog.index‘);
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     
*/
    public function create()
    {
        //
        return View::make(‘blog.create‘);
    }
    /**
     * Store a newly created resource in storage.
     *
     * @return Response
     
*/
    public function store()
    {
        $Input = Input::all();
        $rules = array(
            ‘username‘  => ‘required‘,
            ‘password‘  => ‘required‘,
            ‘rpassword‘ => ‘required|same:password‘,
            ‘email‘     => ‘required|email‘,
            ‘sex‘       => ‘required|boolean‘
        );
        $validator = Validator::make($Input, $rules);
        if ($validator->fails())
        {
          //dd(‘123‘);
          return Redirect::to(‘/create‘)->withErrors($validator, ‘login‘);
        }
          //  dd(‘456‘);
        return Redirect::to(‘/‘);
    }
3.form 表單驗證
{{ Form::open(array(‘url‘ => ‘blog/store‘, ‘method‘ => ‘post‘)) }}
        <div class="form-group">
            <label >使用者名稱:</label>
            {{ Form::text(‘username‘,‘‘,[‘class‘=>‘form-control‘,‘placeholder‘ => ‘username‘]) }}
        </div>      
        <div class="form-group">
            <label >密  碼:</label>
            {{ Form::password(‘password‘,[‘class‘=>‘form-control‘,‘placeholder‘ => ‘Password‘]) }}
        </div>      
        <div class="form-group">
            <label >重複密碼:</label>
            {{ Form::password(‘rpassword‘,[‘class‘=>‘form-control‘,‘placeholder‘ => ‘RePassword‘]) }}
        </div>      
        <div class="form-group">
            <label >郵箱:</label>
            {{ Form::text(‘email‘,‘‘,[‘class‘=>‘form-control‘,‘placeholder‘ => ‘email‘]) }}
        </div>      
        <div class="form-group">
            <label for="exampleInputFile">上傳照片:</label>
            {{ Form::file(‘file‘, [‘class‘ => ‘file‘]) }}
            <p class="help-block">Example block-level help text here.</p>
        </div>
        <div class="form-group">
            <label for="exampleInputFile">性別:</label>
            {{ Form::radio(‘sex‘,‘1‘) }}男  {{ Form::radio(‘sex‘,‘0‘) }}女
        </div>
        <div class="form-group">
           {{ Form::submit(‘提交‘, array(‘class‘ => ‘btn btn-primary‘)) }}
           {{ Form::button(‘取消‘, array(‘class‘ => ‘btn btn-default‘)) }}
        </div>      
        <div class="alert alert-danger" role="alert">
            {{ $errors->login->first() }} 
        </div>      
        {{ Form::close() }}
    </div>
</div>
<script type="text/javascript">
    $(‘.alert‘).delay(800).slideUp();  
</script>
4.引入css檔案和js檔案
    {{ HTML::style(‘blog/css/bootstrap.min.css‘) }}
    {{ HTML::script(‘blog/js/jquery-1.8.3.min.js‘) }}
    {{ HTML::script(‘blog/js/bootstrap.min.js‘) }}

laravel架構中註冊資訊驗證

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.