3

I'm working on a form (without MySQL for the moment) in order to get a data from an input with a confirm message page like "Congratulations $pseudo, your subscribe is successful".

Problem : I can't display the data what I inserted into my form.

Guideline : I think the problem is on my controller in the postUsers method but I don't know how to resolve it.

Here is my form (subscribe.blade.php)

@extends('template')

@section('contenu')
<div class="container">
<h1>Inscription</h1>
{!! Form::open(['url' => 'users/confirm']) !!}
    <div class="form-group has-feedback {!! $errors->has('pseudo') ? 'has-error' : '' !!}">
        <label for="pseudo">Pseudonyme</label>
        {!! Form::text('pseudo', null, ['class' => 'form-control', 'id' => 'id_pseudo', 'placeholder' => 'Votre pseudonyme']) !!}
        {!! $errors->first('pseudo', '<small class="help-block">:message</small>') !!}
    </div>
{!! Form::submit('Inscription', ['class' => 'btn btn-default']) !!}
{!! Form::close() !!}
</div>
@endsection

Here is the confirm page (confirm.blade.php)

@extends('template')

@section('contenu')
<br>
<div class="col-sm-offset-3 col-sm-6">
    <div class="panel panel-info">
        <div class="panel-heading">Validation</div>
        <div class="panel-body">
           Féicitations<?php Request::input('pseudo')?>, vous êtes inscrit sur le site ! Vous pouvez dès à présent vous connecter.
        </div>
    </div>
</div>
@endsection

Here is my routes (routes.php)

Route::get('users', 'UsersController@getUsers');
Route::get('users', 'UsersController@postUsers');

And the controller (UsersController.php)

class UsersController extends Controller
{
public function getUsers(){ 
    return view('confirm');
}

public function postUsers(Request $request){ 
    return 'Le nom est ' . $request->input('pseudo');
}
}

I hope it can helps you to resolve this little problem, I'm following a course about laravel and this framework is facinating for me ^^

Thank you a lot for taking time on my problem. Have a nice day :)

1 Answers1

2

You should use POST instead of GET when you're submitting form. Also, you're using wrong URL, so try to change this:

Route::get('users', 'UsersController@postUsers');

to this:

Route::post('users/confirm', 'UsersController@postUsers');

If you want to display data in confirm view, do something like this:

public function postUsers(Request $request){ 
    return view('confirm', ['pseudo' => $request->pseudo]);
}

and view:

....
<div class="panel-body">
    Féicitations {{ $pseudo }}, vous êtes inscrit sur le site ! Vous pouvez dès à présent vous connecter.
</div>
....
Alexey Mezenin
  • 158,981
  • 26
  • 290
  • 279
  • Thank you, it will help me for other forms. I just need to display my input with the confirm.blade.php –  Aug 06 '16 at 11:24
  • It works but I need to understand. Why use an array as a second parameter on the postUsers method ? –  Aug 06 '16 at 11:49
  • 1
    Second parameter is data which you pass to a view from a controller. https://laravel.com/docs/5.2/views#passing-data-to-views – Alexey Mezenin Aug 06 '16 at 11:53
  • 1
    I understand, so thank you for your expertise, it helps me a lot. –  Aug 06 '16 at 11:55