ferenan ferenan - 6 months ago 12
PHP Question

Forms showing up as plain text in Laravel 5

I'm pretty new to the Laravel universe.

So I was following a tutorial on OpenClassrooms and the tutorial is about Laravel 4 and I'm using Laravel 5, so I went through some trouble trying to adapt my controllers and getting them to work on my project, and after getting rid of many errors concerning the namespace dependencies, I'm getting a form which looks like text html that is not processed, here's what's showing up:

<form method="POST" action="http://gappsl/users" accept-charset="UTF-8">
<input
name="_token"
type="hidden"
value="HMfnLvctXZqOuCpSdeJXML76L2KoPsZtadpIqOnm">
<label for="nom">Enter your name:</label>
<input name="nom" type="text" id="nom">
<input type="submit" value="Submit">
</form>


Here's my controller:

<?php namespace App\Http\Controllers; use \View;
class UsersController extends Controller {
public function getInfos() {
return View::make('infos');
}

public function postInfos() {
echo 'The name is ' . Input::get('nom');
}
}
?>


Here's my views:

@extends('tempform')
@section('content') {{ Form::open(array('url'=>'users')) }} {{ Form::label('nom', 'Enter your name:') }} {{ Form::text('nom') }} {{ Form::submit('Submit') }} {{ Form::close() }}
@stop

<!doctype html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<body>
<p> @yield('content') </p>
</body>
</html>


I hope you can help me.

Answer

In Laravel 5, {{ }} (for example {{ Form::open() }} escapes the variables in blade templates.

In Laravel 5, use {!! Form::open() !!} instead. Also, double check that it actually is a blade template you're using (and not a straight up PHP one).