如何使用laravel中的链接预先填充HTML表单字段?

时间:2018-08-09 09:31:27

标签: php laravel

我在下面有注册代码。我想从name之类的链接中预先填充其表单字段positionmydomain.com/register?ref=abc

<form class="form-signin" action="{{ route('register') }}" method="post" name="form">
 {{csrf_field()}}
<div class="row">
<div class="col-md-6">
<label for="fullname">Referrer Name</label>
<input class="form-styling" type="text" value="{{old('ref_name')}}" id="ref_name" required placeholder=""/>
<div id="ref">

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

我尝试过:

app('request')->input('ref') in name fied

它会预先填充,但不会对该预先填充的名称进行验证。

验证码:

@if ($errors->has('referrer_id'))
<span class="help-block">
 <strong>{{ $errors->first('referrer_id') }}</strong>
   </span>
   @endif

1 个答案:

答案 0 :(得分:0)

标签必须分配给输入的ID,验证必须分配给输入的名称。

<label for="fullname">Referrer Name</label>
<input class="form-styling" type="text" value="{{ old(request()->query('referrer_id')) }}" name="{{ request()->query('referrer_id') }}" id="fullname" required placeholder=""/>

和称呼

@if ($errors->has(request()->query('referrer_id')))
  <span class="help-block">
    <strong>{{ $errors->first(request()->query('referrer_id')) }}</strong>
  </span>
@endif