Agree with th-6ren">
gpt4 book ai didi

php - Laravel 5.2 在寄存器中添加条款和条件

转载 作者:可可西里 更新时间:2023-11-01 00:29:40 25 4
gpt4 key购买 nike

我想在我的注册验证表中添加条款和条件,但它不起作用。谁能帮我解决这个问题。

查看

<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>

授权 Controller

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

因为我们保留了文本框、文本区域等的旧值,以防输入的旧值未通过验证,但在您的情况下,复选框需要一个静态值,即 1 或任何值。如果未选中则显示错误,但其值保持不变。

关于php - Laravel 5.2 在寄存器中添加条款和条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40647266/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com