zoukankan      html  css  js  c++  java
  • laravel框架中注册信息验证

    1.路由配置
    <?php
    Route::get('/',['as'=>'blog.index','uses'=>'BlogController@index']);
    Route::get('/create',['as'=>'blog.create','uses'=>'BlogController@create']);
    Route::post('blog/store',['as'=>'blog.store','uses'=>'BlogController@store']);
     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') }}
  • 相关阅读:
    258. Add Digits 数位相加到只剩一位数
    7. Reverse Integer 反转整数
    9. Palindrome Number 回文数的判断
    824. Goat Latin山羊拉丁文
    819. Most Common Word 统计高频词(暂未被禁止)
    Angular 2 模板语法
    HTML DOM Style opacity 属性
    Basic concepts (C language) – C 中文开发手册
    JavaScript手册 | JS Array 对象中的fill()方法
    HTML <form> 标签
  • 原文地址:https://www.cnblogs.com/qhorse/p/4701155.html
Copyright © 2011-2022 走看看