将输入(表单)从页面传递给自身

时间:2014-02-20 08:58:35

标签: php forms laravel laravel-4 laravel-routing

我正在制作我的第一个laravel脚本,尝试提交表单并在同一页面上查看输入。我正在研究这个问题好几天,希望有人可以解决这个问题。问题是我收到了这个错误:

Undefined variable: data (View: D:\Programmer\wamp\www\laravel\app\views\bassengweb.blade.php)

查看:Bassengweb.blade.index

@extends('master')

@section('container')
<h1>BassengWeb testrun</h1>
<table>
{{ Form::open(array('route' => 'bassengweb', 'url' => '/', 'method' => 'post')) }}
<tr>
    <td>{{ Form::label('bassengId', 'Basseng ID')}}</td>
    <td>{{ Form::text('bassengId') }}</td>
</tr>
<tr>
    <td>{{ Form::label('frittKlor', 'Fritt Klor')}}</td>
    <td>{{ Form::text('frittKlor') }}</td>
</tr>
<tr>
    <td>{{ Form::label('bundetKlor', 'Bundet Klor')}}</td>
    <td>{{ Form::text('bundetKlor') }}</td>
</tr>
<tr>
    <td>{{ Form::label('totalKlor', 'Total Klor')}}</td>
    <td>{{ Form::text('totalKlor') }}</td>
</tr>
<tr>
    <td>{{ Form::label('ph', 'PH')}}</td>
    <td>{{ Form::text('ph') }}</td>
</tr>
<tr>
    <td>{{ Form::label('autoPh', 'Auto PH')}}</td>
    <td>{{ Form::text('autoPh') }}</td>
</tr>
<tr>
    <td>{{ Form::submit('Lagre målinger') }}</td>
{{ Form::close() }}
</table>


@if($data)
    {{ $data->bassengId }}
@endif
@stop

Homecontroller.php

<?php

class HomeController extends BaseController {

    public function showWelcome()
    {
        return View::make('hello');
    }

    public function showTest()
    {
        return View::make('test');
    }

    public function getInput()
    {
        $input = Input::all();
        print_r($input); die();
        return View::make('bassengweb')->with('data', '$input');
    }
}

view:master.blade.php

<div class="container">
    @yield('container')
</div>

routes.php文件

Route::get('/', function()
{
    return View::make('bassengweb');
});

//Route::post('/', array('uses'=>'HomeController@getInput'));

Route::post('/',function(){
$input = Input::all();
//for inspecting  input
print_r($input);
die();
//to send input to view but before sending to view comment last two lines
return View::make('bassengweb')->with('data',$input);

2 个答案:

答案 0 :(得分:0)

您在HomeController.php中用单引号括起$ input,而不是尝试:

<?php

class HomeController extends BaseController {
public function showWelcome()
{
    return View::make('hello');
}

public function showTest()
{
    return View::make('test');
}

public function getInput()
{
    $input = Input::all();
    print_r($input); die();
    return View::make('bassengweb')->with('data', $input);
}

}

答案 1 :(得分:0)

routes.php中,稍微更改路线注册。

Route::get('/', function()
{
    $data = Input::all();
    return View::make('bassengweb', compact('data'));
});