php – Laravel 5.2在注册表中添加条款和条件

我想在我的注册表的验证表单中添加条款和条件,但它不起作用.有人可以帮我弄这个吗.

视图

<div class="form-group{{ $errors->has('terms') ? ' has-error' : '' }}">
  <label>
    <input type="checkBox" class="form-control" name="terms" value="{{ old('terms') }}" /> Agree with the terms and conditions
  </label>

  <div class="col-md-4">
    @if ($errors->has('terms'))
     <span class="help-block">
       <strong>{{ $errors->first('terms') }}</strong>
     </span>
    @endif
  </div>
</div>

AuthController

protected function validator(array $data)
    {
        return Validator::make($data, [
            'name' => 'required|max:255',
            'company' => 'required|max:255',
            'email' => 'required|email|max:255|unique:users',
            'telephone' => 'required|max:255',
            'password' => 'required|min:6|confirmed',
            'g-recaptcha-response' => 'required|captcha',
            'terms' => 'required'
          ]);

    }

解决方法:

更改以下行:

<input type="checkBox" class="form-control" name="terms" value="{{ old('terms') }}" /> Agree with the terms and conditions

<input type="checkBox" class="form-control" name="terms" value="1" /> Agree with the terms and conditions

因为我们维护textBox,textarea等的旧值,以防输入的旧值未通过验证,但在您的情况下复选框需要静态值,即1或任何值.
如果未选择显示错误,但其值保持不变.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...