Passing input (form) from a page to itself

2019-08-30 11:30发布

I am working on my first laravel script, trying to submit a form and see the input on the same page. I am working on this problem for days, hopefully someone can solve this. The problem is that i get this error:

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

view: 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条回答
爷的心禁止访问
2楼-- · 2019-08-30 12:05

You enclosed $input in single quotes in your HomeController.php, instead try:

<?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);
}

}

查看更多
孤傲高冷的网名
3楼-- · 2019-08-30 12:28

In your routes.php, change route registration a little.

Route::get('/', function()
{
    $data = Input::all();
    return View::make('bassengweb', compact('data'));
});
查看更多
登录 后发表回答