I'm trying to use the php upload_progress feature with symfony2. I set my session.upload_progress.prefix and session.upload_progress.name in my php.ini.
My form below :
<form id="form-import-file" action="" method="post" {{ form_enctype(form) }} class="form-horizontal">
{{ form_widget(form.file, { 'attr':{'class':'input-file-import'}}) }}
{{ form_rest(form) }}
{{ form_errors(form.file) }}
<input type="hidden" name="{{ upload_progress_name }}" value="123" />
<button type="submit" class="btn btn-success">Submit</button>
</form>
where upload_progress_name = ini_get("session.upload_progress.name").
The upload is okay, but the session doesn't show any upload infos.
Any help ?
Ensure that <input type="hidden" name="{{ upload_progress_name }}" value="123" />
is before the file input fields. Just place it under the form tag.
Also what helped me out is this list: issues on php upload progress
Finally there is good symfony2-bundle, which may help you to not reinvent everything new.OneUpBundle
With this bundle you can pick a Frontend solution or create your own one.
Related
I am following a tutorial about Laravel.
However, I want to convert the blade template Form::open() to html/php form, to make it easier to read & understand.
This is the Blade template:
{{ Form::open(['action'=> ['StudentController#destroy', $student->id], 'method'=>'POST']) }}
{{ method_field('DELETE') }}
{{ Form::submit('Delete',['class'=>'btn btn-danger']) }}
{{ Form::close() }}
I need to convert the blade code to html/php
I tried it multiple times, something like this. but failed.
<form action="url('StudentController#destroy', $student->id)" method="POST">
<?php method_field('Delete'); ?>
<button class="btn btn-danger" type="submit">Delete</button>
</form>
Anyone know the correct html/php form?
[edit] Route:list
try this way
use {{}} and use route
<form action="{{route('StudentController#destroy', ['id'=>$student->id])}}" method="POST">
<?php method_field('Delete'); ?>
<button class="btn btn-danger" type="submit">Delete</button>
</form>
To call a controller action you need to use url()->action(...) (or action()) for short.
<form action="{{url()->action('StudentController#destroy', ['id'=>$student->id])}}" method="POST">
#csrf
{{ method_field('DELETE'); }}
<button class="btn btn-danger" type="submit">Delete</button>
</form>
This is also described in the manual
you should use this code
<form action="{{ url('StudentController#destroy', $student->id) }}" method="POST">
<input type='_method' value='DELETE' />
<button class="btn btn-danger" type="submit">Delete</button>
</form>
In your 'action' on the form, you need to enclose any helper functions within brackets so that Blade knows what to do with this, otherwise, it's just text.
Also note, I removed 'method_field' and replaced it with the hidden field, as this is essentially what method_field helper creates.
<form action="{{route('StudentController#destroy', ['id' => $student->id])}}" method="POST">
<input type='hidden' value='DELETE'>
<button class="btn btn-danger" type="submit">Delete</button>
</form>
If using the route helper isn't working, you could use a more simple approach for the 'action' param of the form tag:
<form action="/student/destroy/{{$student->id}}" method="POST">
How can I create multiple requests for the same route like below.
Route.php
Route::get('/home', 'HomeController#index');//->middleware('auth');
Route::get('/home/{$user}','HomeController#showStudent');
Route::delete('/home/{$studentId}','HomeController#deleteStudent');
the form was working fine until I have added the delete request. In my blade template I have code something like this.
home.blade.php
<form class="" role="form" method="DELETE" action="/home/{{$student->id}}">
{{ csrf_field() }}
<td><button type="submit" class="btn btn-primary pull-right">Remove Student</button></td>
</form>
I believe because of the same routes it's showing NotFoundHTTPException.
On one route /home I am trying to Add, Show, Edit and Delete a record with different buttons.
Thanks in Advance.
You could add a form and use Laravel's Form Method Spoofing
<input type="hidden" name="_method" value="DELETE">
See more here...http://laravel.com/docs/master/routing#form-method-spoofing
Try as below....
<form class="" role="form" method="DELETE" action="/home/{{$student->id}}">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<td><button type="submit" class="btn btn-primary pull-right">Remove Student</button></td>
</form>
1) Change you route from:
Route::delete('/home/{$studentId}','HomeController#deleteStudent');
To:
Route::get('/delete/{$Id}','HomeController#deleteStudent')->name('delete');
2) change you form tag from:
<form class="" role="form" method="DELETE" action="/home/{{$student->id}}">
To:
<form class="" role="form" method="get" action="route('delete', ['id' => $student->id])">
HTML forms doesn't support methods other than get and post. If you need to simulate it, include a hidden input to simulate delete:
<input name="_method" type="hidden" value="DELETE">
Then in your code, update it to:
<form class="" role="form" method="POST" action="/home/{{$student->id}}">
{{ csrf_field() }}
<input name="_method" type="hidden" value="DELETE">
<td><button type="submit" class="btn btn-primary pull-right">Remove Student</button></td>
</form>
Reference:
Are the PUT, DELETE, HEAD, etc methods available in most web browsers?
http://laraveldaily.com/theres-no-putpatchdelete-method-or-how-to-build-a-laravel-form-manually/
I am using laravel 5.2 and I am unable to delete article in laravel. Below is my view link:
<form method="DELETE" action="/article/{{ $article->id }}">
{{ csrf_field() }}
<button class="btn btn-danger" type="submit">Delete</button>
</form>
Below is my controller code:
public function destroy($id)
{
Article::destroy($id);
Session::flash('msg','Article deleted successfully');
return redirect()->back();
}
Below are route listing:
HTML forms don't actually support any methods other than GET and POST. To get around this Laravel spoofs the method and then picks this up in the request.
From the docs:
HTML forms do not support PUT, PATCH or DELETE actions. So, when
defining PUT, PATCH or DELETE routes that are called from an HTML
form, you will need to add a hidden _method field to the form. The
value sent with the _method field will be used as the HTTP request
method
As such, you just need to alter your form like so:
<form method="POST" action="/article/{{ $article->id }}">
{{ csrf_field() }}
<input type="hidden" name="_method" value="DELETE">
<button class="btn btn-danger" type="submit">Delete</button>
</form>
You can also generate the _method with {{ method_field('DELETE') }} using Blade.
In your view file what you need to do is...
<form method="POST" action="/article/{{ $article->id }}">
<input type="hidden" name="_method" value="DELETE">
{{ csrf_field() }}
<button class="btn btn-danger" type="submit">Delete</button>
</form>
I already had a post that lead to this question but now I isolated one problem and so its better to make a new clean post :
Symfony 2.1.3 with jordillonch/CrudGeneratorBundle
I used this CrudGenerator on an entity in which I have 2 timestampable fields that need to be updated automatically :
I installed Gedmo for the timestampable funtionnality.
The fields are :
cree_le (in english created_at) : #Gedmo\Timestampable(on="create")
and modifiele (in english updated_at) - #Gedmo\Timestampable(on="update")
The problem is that I want to customize the form to show only the fields to update by the user.
When I use the not customized edit.html.twig using {{ form_widget(edit_form) }} the update is working but the values of updated_at are not changed because the old value is submitted with the form.
I tried several things to customize the form but I did not yet find the solution.
This version of customized edit.html.twig is not working because the submitted form is not valid :
<form class="well" action="{{ path('employee_update', { 'id': entity.id }) }}" method="post" {{ form_enctype(edit_form) }}>
<input type="hidden" name="_method" value="PUT" />
<div>
{{ form_label(edit_form.nom) }}
{{ form_errors(edit_form.nom) }}
{{ form_widget(edit_form.nom) }}
</div>
<div>
{{ form_label(edit_form.email) }}
{{ form_errors(edit_form.email) }}
{{ form_widget(edit_form.email) }}
</div>
<div>
{{ form_label(edit_form.telephone, 'Téléphone') }}
{{ form_errors(edit_form.telephone) }}
{{ form_widget(edit_form.telephone) }}
</div>
<div>
{{ form_label(edit_form.actif) }}
{{ form_errors(edit_form.actif) }}
{{ form_widget(edit_form.actif) }}
</div>
<input type="hidden" id="too_employeebundle_employee_cree_le" name="too_employeebundle_employee[cree_le]" value="{{ entity.creele|date('Y-m-d H:i:s') }}">
<input type="hidden" id="too_employeebundle_employee_modifie_le" name="too_employeebundle_employee[modifie_le]" value="{{ entity.modifiele|date('Y-m-d H:i:s') }}">
{{ form_widget(edit_form._token) }}
<p>
<button type="submit" class="btn btn-success">{{ 'views.edit.editbutton'|trans({}, 'JordiLlonchCrudGeneratorBundle') }}</button>
</p>
</form>
Sure I'm doing something wrong but who could tell me how to go on ?
Remove cree_le and modifiele from your Form Class and dont render them on your template.
Then let Timestampable do his job! when you create something the cree_le value will be automatic set. When you change something the modifiele value will be automatic set too.
I have Customer Controller with index, edit, update methods
Route::resource('customer', 'CustomerController');
Controller methods update
public function update($id) { echo $id; }
my HTML Form
<form action="/customer/1" method="post">
<input type="text" name="email" value="" />
<input type="submit" value="" />
</form>
I have following a Documentation here
http://four.laravel.com/docs/controllers#resource-controllers
PUT/PATCH /resource/{id} update
It's seems not working for me, how to use it? thank you
To use the PATH, PUT or DELETE HTML methods you need to add a hidden input with _method. Like the following...
<input type="hidden" name="_method" value="PUT" />
You can use the Form Builder. Example using blade:
{{ Form::open(array('method' => 'DELETE')) }}
That will automatically add this for you
<input name="_method" type="hidden" value="DELETE">
This works for me in Laravel 4:
{{ Form::open(array('url' => URL::to('customer/1'), 'method' => 'PUT')) }}
I am using Laravel resource controller. For update a page, I copied it from insert page after then
Just I added an extra field to update view like as
{{ method_field('put') }}
Just use this as for update
<form method="post" action="{{ URL::to('customer',$customer['id'])}}">
{{ csrf_field() }}
{{ method_field('put') }}