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']) !!}
Related
this is my form in my view
{!! Form::open(['url' => ['documents/{file}/{id}', $file->name, $file->id],'method' => 'delete']) !!}
{!! Form::token() !!}
{!! Form::submit('Delete') !!}
{!! Form::close() !!}
controller in which i delete file from database and the original file
public function destroyFile($file_name, $id)
{
File::findOrFail($id)->delete();
$file_path = storage_path('documents').'/'.$file_name;
$destinationPath = $file_path; File::delete($file_path);
return redirect('/documents');
}
This is the route
Route::delete('documents/{file}/{id}','FilesController#destroyFile');
And when i press submit button I get NotFoundHttpException
Try to use this
{!! Form::open(['method' => 'DELETE', 'action' => ['FilesController#destroyFile', $file->name, $file->id] ]) !!}
Actually, their answers are correct. You need the _method to be DELETE. When I am using this. Laravel do it for me.
Or you can put this on your form
<input type="hidden" name="_method" value="DELETE">
or
{!! Form::hidden('_method', 'DELETE') !!}
It is not possible to use this method with html forms in most browsers, most only support GET and POST.
So the reason for this request not working is because the browser sends this as a GET request, wich is the default.
GET, POST, PUT and DELETE are however supported in most major browsers when using XMLHttpRequests (ajax).
add {{ method_field('DELETE') }} to your form .
{!! Form::open(['url' => ['documents/{file}/{id}', $file->name, $file->id],'method' => 'delete']) !!}
{{ method_field('DELETE') }}
{!! Form::token() !!}
{!! Form::submit('Delete') !!}
{!! Form::close() !!}
The reason is that HTML forms does not support PUT, PATCH, DELETE actions. Basically you need to spoof them as described here. https://laravel.com/docs/5.2/routing#form-method-spoofing
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
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') !!}
im trying to buld a complate form using laravel but i cant make this right :
<form class="form-horizontal">
<fieldset>
{{Form::open(array('url'=>'register'))}}
but clearly this does not do anything with my data base so i want this :
<form class="form-horizontal" action={{ url('our/target/route') }}" method="post">
but when i do this my form is not horizontal anymore and becomes something un watchable
so what is the problem ?
Now you have two <form>
Try this:
{{ Form::open(array('url' => 'register', 'class' => 'form-horizontal')) }}
<fieldset>
I'm trying to make an image uploader, but it always give me this error
Call to a member function getClientOriginalName() on a non-object
here is my code controller code
public function uploadImageProcess(){
$destinatonPath = '';
$filename = '';
$file = Input::file('image');
$destinationPath = public_path().'/assets/images/';
$filename = str_random(6).'_'.$file->getClientOriginalName();
$uploadSuccess = $file->move($destinationPath, $filename);
if(Input::hasFile('image')){
$images = new Images;
$images->title = Input::get('title');
$images->path = '/assets/images/' . $filename;
$image->user_id = Auth::user()->id;
Session::flash('success_insert','<strong>Upload success</strong>');
return Redirect::to('user/dashboard');
}
}
and here is the upload form
<form role="form" action="{{URL::to('user/poster/upload_process')}}" method="post">
<label>Judul Poster</label>
<input class="form-control" type="text" name="title">
<label>Poster</label>
<input class="" type="file" name="image"><br/>
<input class="btn btn-primary" type="submit" >
</form>
what's wrong with my code?
You miss enctype attribute in your form markup.
Either do this
<form role="form" action="{{URL::to('user/poster/upload_process')}}" method="post" enctype="multipart/form-data">
...
</form>
or this...
{{ Form::open(array('url' => 'user/poster/upload_process', 'files' => true, 'method' => 'post')) }}
// ...
{{ Form::close() }}
These code are right, but you didn't check values of returns of Input::file('image'). I think returns value may be is not a correct object or your class Input does not have a public function name is getClientOriginalName.
Code:
$file = Input::file('image');
var_dump($file); // if return a correct object. you will check your class Input.
Good luck.
This is just because you forget to write enctype="multipart/form-data" in <form> tag.
This error happen just when you forget this:
<form class="form form-horizontal" method="post" action="{{ route('articles.store') }}" enctype="multipart/form-data">
Please Check Your Form 'files'=> true
{!! Form::open(['route' => ['Please Type Url'], 'class' => 'form-horizontal' , 'files' => true]) !!}
{!! Form::open(array('url' => '/xyz','files' => true)) !!}
{!! Form::close() !!}
if you are using Laravel Collective than you can try this solution
{{ Form::open(array('url' => 'user/poster/upload_process', 'files' => true, 'method' => 'post')) }}
{{ Form::close() }}
else if you are using html form tag than you have to put extra markdown for storing image data
<form class="form form-horizontal" method="post" action="{{ route('user/poster/upload_process') }}" enctype="multipart/form-data">