Passing input (form) from a page to itself

梦想与她 提交于 2019-12-12 00:58:11

问题


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

回答1:


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

}




回答2:


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

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


来源:https://stackoverflow.com/questions/21902782/passing-input-form-from-a-page-to-itself

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!