alt*_*ids 3 php laravel blade laravel-5
我有一个变量$country_code
,它在我的表单的一个部分显示正确的值,但不是在不同的部分.为什么会这样?
这是我的代码:
{{ Form::open(['action' => ['PinVerificationController@valid'],'id'=>'pin_code_form']) }}
//$country_code shows 1
We sent a text message to {{$country_code}} {{$phone_number}}. You should receive it within a few seconds.<br><br>
{{ Form::label('Pin Code', null, ['class' => 'control-label']) }}
{{ Form::hidden('country_code', $country_code) }}//<------shows 1-US instead of 1
{{ Form::hidden('phone_number', $phone_number) }}
{{ Form::hidden('type', $pin_notification_type) }}
{{ Form::text('pin_code', null,['placeholder' => 'Pin Code'])}}<br><br>
Enter a 4 digit pin you received by phone.
<br>
<br>
{{ Form::submit('Verify',['name'=>'validate'])}}
{{ Form::close() }}
Run Code Online (Sandbox Code Playgroud)
因此,如果我在控制器中将$ country_code设置为"1",它将显示我们发送了一条短信给1 5555555.你应该在几秒钟内收到它.
但是,如果我在隐藏的表单上执行检查元素,则会显示1-US.我试过了php artisan view:clear
,php artisan clear-compiled
但问题仍然存在.
我也试过硬编码值{{ Form::hidden('country_code', 'asdf') }}
,我没有看到变化.我尝试添加测试{{ Form::hidden('country_code1', 'asdf') }}
并查看更新.
我也改名country_code
到country_code111
我的隐藏字段,它显示的1正确的价值我认为这是一个缓存的问题,但就像我提到我已经试过php artisan cache:clear
,问题依然存在.
由于您使用的是Laravel 5.4,我假设您使用Form
的是LaravelCollective,因为它们是从5.x中的基线Laravel中删除的.
如果LaravelCollective Forms存在于请求数据中或旧发布的数据(old()
函数)中,它将覆盖您提供给输入的值.我怀疑你是这样的.
您可以在此处查看此行为实现.
要解决此问题,您有以下几种选择:
Form::
用来生成表单,只需使用经典的html/Blade自动创建隐藏的输入就个人而言,我建议#3,因为那样你就可以完全控制你的代码了.
<input type="hidden" name="country_code" value="{{ $country_code }}"/>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
672 次 |
最近记录: |