Why is my laravel 5 rendering html as string instead of dom? - php

So I have written the following route:
Route::get('/login', function() {
return View::make('login.form');
});
This is the view:
#extends('layouts.master')
#section('content')
<div class="form-section">
{{ Form::open(
array(
'url' => 'login-submit',
'method' => 'POST'
)
)
}}
{{ Form::submit('Authorize With AisisPlatform') }}
{{ Form::close() }}
#stop
This is exactly what I see when I look at the page:
<form method="POST" action="http://app-response.tracking/login-submit" accept-charset="UTF-8"><input name="_token" type="hidden" value="7xHzX20h1RZBnkTP2CRraZVsAfSQIfVP61mBiFtN"> <input type="submit" value="Authorize With AisisPlatform"> </form>
Um..... Shouldn't the form be well .... and actual form? Why did it render out the html as a string? How do I make it render the actual form submit button?

The default echo braces: {{ ... }} escape HTML by default, to prevent HTML injection.
You should use {!! .. !!} to print raw HTML. For example:
{!! Form::submit('Authorize With AisisPlatform') !!}

Related

Symfony - Form not redirecting to action specified in form

I'm trying to make a form, which I self-defined the action like this in my controller:
$form = $this->createForm(ProgrammeSearchType::class, $search, [
'action' => $this->generateUrl('recherche_programme'),
'method' => 'GET',
]);
But, the form rendered in the view look like this:
<form id="myForm">
{{fields.....}}
</form>
So.. there is a problem. Why "action" is not specified in the HTML while I defined it into the controller.
Regards
Symfony doc: https://symfony.com/doc/current/forms.html#changing-the-action-and-http-method
Use {{ form_start(form) }} and {{ form_end(form) }} instead of <form> ... </form> tags in your view template.

How to submit a form using PUT http verb in Laravel

I know that this question may have been made but I just can't get it to work. if someone could help me I would be very grateful. I have colletive/form installed but the answer can be an html form tag too.
Now listing my form, my route and my exception.
{{ Form::model( array('route' => array('casas.update', 238), 'method' => 'PUT')) }}
<input type="hidden" name="_method" value="PUT">
-
Route::resource('casas', 'CasasController');
exception:
MethodNotAllowedHttpException in RouteCollection.php line 218:
With plain html / blade
<form action="{{ route('casas.update', $casa->id) }}" method="post">
{{ csrf_field() }}
{{ method_field('put') }}
{{-- Your form fields go here --}}
<input type="submit" value="Update">
</form>
Wirth Laravel Collective it may look like
{{ Form::model($casa, ['route' => ['casas.update', $casa->id], 'method' => 'put']) }}
{{-- Your form fields go here --}}
{{ Form::submit('Update') }}
{{ Form::close() }}
In both cases it's assumed that you pass a model instance $casa into your blade template
In your controller
class CasasController extends Controller
{
public function edit(Casa $casa) // type hint your Model
{
return view('casas.edit')
->with('casa', $casa);
}
public function update(Request $request, Casa $casa) // type hint your Model
{
dd($casa, $request->all());
}
}

Laravel 5.1 form - 'files' => true

I use Laravel HTML to create form but I have problem, so in creating form I have:
{!! Form::open(['url'=>'vocuhers','files' => 'true','enctype'=>'multipart/form-data']) !!}
#include('vouchers.form',['submitButtonText'=>'Click to Add New Vocuher'])
{!! Form::close() !!}
But when I see my HTML form in browser there is just:
<form method="POST" action="http://localhost:8888/vouchers" accept-charset="UTF-8">
<input name="_token" type="hidden" value="dfgdfgdfgdfgdf">
so where is
enctype="multipart/form-data"
which allow me to upload files from form ?
Why I don't get this HTML output:
<form method="POST" action="https://bedbids.com/chats" accept-charset="UTF-8" enctype="multipart/form-data">
<input name="_token" type="hidden" value="dsfdfgdfgdfgdfg">
What is the problem here exactly ?
Your syntax is wrong. The following works for me:
{{Form::open(array('url' => 'your_url', 'method' => 'post', 'files' => true))}}
Change url with route as below.
{{!! Form::open(['route'=>'vocuhers','class'=>'your_class','files'=>true]) !!}}
{!! Form::open(['url'=>'vocuhers','files' => 'true','enctype'=>'multipart/form-data']) !!}
change It to
{!! Form::open(['url'=>'vocuhers','files' =>true,'enctype'=>'multipart/form-data']) !!}
as Markinson said
Change it to like this:
{!! Form::attributes(['enctype'=>"multipart/form-data"])open(['url'=>'vocuhers']) !!}

How to use relative url in Laravel 5 forms?

In my view, I have
{!! Form::open(['url'=>'/foo/bar']) !!}
This generates the following html
<form method="POST" action="http://localhost/foo/bar" accept-charset="UTF-8">
<input name="_token" value="5GnCAyo2v076FfvnF51jWbiddCdLX138TMxQl83c" type="hidden">
</form>
The generated action is an absolute URL. How can I use Form::open() to create a relative URL?
I do not want action="http://localhost/foo/bar", instead I want action="/foo/bar".
Need a little change in your code:
{!! Form::open(['url'=>'foo/bar']) !!}
try with this.
Try this
{!! Form::open(['url'=> url('foo/bar')]) !!}
you'll get http://site-url/foo/bar
or
{!! Form::open(['url'=> 'foo/bar']) !!}
but you'll get http://site-url/your/current/url/foo/bar

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.
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).
for Laravel Framework version 5.2.34 this worked for me
{!! Form::open(array('url' => '/admin/expertise')) !!}
{!! Form::close() !!}
with one { and two !! .

Categories