【问题标题】:Blade Templating Input Type Value刀片模板输入类型值
【发布时间】:2014-09-26 07:26:20
【问题描述】:

在 Html 形式中,我可以这样做:

<input type="hidden" name="token" value="{{ $token }}">

我想在这样的完整刀片模板中执行此操作:

{{ Form::hidden('token', $token, array('class' => 'form-control')) }}  

但是第二个选项没有传递$token 值。我哪里错了?

-- 更新--

我找到了解决方案:

这是一个很简单的问题,但在刀片模板中命名输入时必须小心。

这是我的第一个表单,效果很好:

<form action="{{ action('RemindersController@postReset') }}" method="POST">
    <input type="hidden" name="token" value="{{ $token }}">
    Email<input type="email" name="email">
    Password<input type="password" name="password">
    Password<input type="password" name="password_confirmation">
    <input type="submit" value="Reset Password">
</form>

**在刀片模板形式中就像 **

{{ Form::open(array('action' => 'RemindersController@postReset')) }}
   {{ Form::hidden('token', $token , array('class' => 'form-control')) }} 
   {{ Form::email('email', null, array('class'=>'form-control input-sm','placeholder'=>'Mail address')) }}
   {{ Form::password('pass', array('class'=>'form-control input-sm','placeholder'=>'New Password')) }}
   {{ Form::password('pass_conf', array('class'=>'form-control input-sm','placeholder'=>'Confirm Password')) }}
   {{ Form::submit('Submit', array('class'=>'btn btn-info btn-block')) }}
{{ Form::close() }}

--解决方案--

所以错误是:

在第一种形式中,

Password<input type="password" name="password">
Password<input type="password" name="password_confirmation">

在第二种形式中,

{{ Form::password('pass', array('class'=>'form-control
input-sm','placeholder'=>'New Password')) }} 
{{Form::password('pass_conf', array('class'=>'form-control
input-sm','placeholder'=>'Confirm Password')) }}

输入名称为 passwordpassword_confirmation,在第二种形式中,它们被命名为 passpass_conf

我将 pass 更改为 password 并将 pass_conf 更改为 password_confirmation,现在它工作正常。

感谢您的反馈和耐心。

【问题讨论】:

  • 我猜你的$token 变量是空的
  • 我可以以第一种形式传递值。但在第二个,我不能。如果它为空,我无法传递第一个中的值。

标签: html laravel blade hidden-field


【解决方案1】:

这只是一个猜测,但您也可以尝试输入静态值:

{{ Form::hidden('token', 'some token here', array('class' => 'form-control')) }}  

现在检查它是否在页面源中。

如果不是,则意味着您可能使用 withInput 重定向到表单,然后即使您手动为任何 HTML 表单元素设置值,Larravel 也会使用与之前相同的数据填充表单。

在这种情况下,您可以使用以下方法进行重定向:

->withInput(Input::except('token'));

如果是这种情况,您可以在此主题中阅读更多相关信息:Laravel redirection using withInput doesn't allow to change inputs values

编辑

你应该尝试改变:

return Redirect::back()->with('error', Lang::get($response)); 

进入:

return Redirect::back()->with(array ('error', 'token'), array(Lang::get($response), Input::get('token')); 

【讨论】:

  • 我将令牌值静态地设置为“5aee974a557c3568d93645529220eb27642e566a”,它出现在页面源中。
  • 是的,当我用 {{ $token }} 将令牌放在外面时,它会显示我想要的值。
  • 非常感谢@Marcin 花费您的时间,但错误的解决方案很简单,我更新了我的帖子。再次感谢您分享您的经验。
猜你喜欢
  • 2016-07-07
  • 2014-03-01
  • 1970-01-01
  • 2013-04-29
  • 1970-01-01
  • 2016-10-14
  • 2014-11-19
  • 2017-04-03
相关资源
最近更新 更多