【问题标题】:Pass form value in Laravel to Blade template将 Laravel 中的表单值传递给 Blade 模板
【发布时间】:2014-07-17 23:25:22
【问题描述】:

我正在尝试寻找一种方法将在 Laravel 表单中输入的值传递到操作页面,但找不到正确的语法。

这是我的刀片形式的摘录:

{{ Form::open(array('url' => 'thanks')) }}
 {{ Form::label('email', 'Email Address') }}
 {{ Form::text('email') }}
 {{ Form::submit('Sign Up') }}
{{ Form::close() }}

这是我的路线:

Route::post('thanks',function($email)
{
$theEmail = $email;       
return View::make('thanks', $theEmail);
});

如何更正路线以便在我的thanks.blade.php 页面中使用$theEmail

【问题讨论】:

    标签: forms laravel laravel-4 blade


    【解决方案1】:

    您需要通过Input::get()从发布的表单中获取变量

    Route::post('thanks',function()
    {
       $theEmail = Input::get('email');
       return View::make('thanks')->with('theEmail', $theEmail);
    });
    

    【讨论】:

    • 感谢您的快速回复!我在实施更改时收到此错误:“[2014-05-28 16:13:07] production.ERROR: exception 'ErrorException' with message 'array_merge(): Argument #2 is not an array' in /用户/jlowery/testapp/bootstrap/compiled.php:8909" 想法?
    【解决方案2】:
    Route::post('thanks',function()
    {
       $data = [];
       $data['theEmail'] = Input::get('email');
       return View::make('thanks', $data);
    });
    

    然后在你的刀片文件中

    {{ $theEmail }}
    

    【讨论】:

      【解决方案3】:

      Route::post('thanks',function()

      {

       $email=Input::get('email'); 
      
      
      return View::make('thanks')->with('email',$email);
      
      
      });
      

      【讨论】:

        猜你喜欢
        • 2023-03-14
        • 2014-07-17
        • 2018-06-29
        • 2016-02-05
        • 2015-12-02
        • 2021-06-29
        • 2012-11-24
        • 2013-04-13
        • 2015-07-16
        相关资源
        最近更新 更多