Laravel 5.2 - Form do not submit - laravel

Sorry, i'm very new to Laravel, i have this form:
<form action="/register" method="post">
{!! csrf_field() !!}
....
<div class="form-group">
<button type="button" class="btn btn-default">Register</button>
</div>
</form>
And the route is:
Route::get('/register', 'Auth\AuthController#getRegister');
Route::post('/register', 'Auth\AuthController#postRegister');
When i click on Register button nothing happen... the form do not submit, no errors etc.
Can you help me ?

Change this
<button type="button" class="btn btn-default">Register</button>
to
<button type="submit" class="btn btn-default">Register</button>
and always use dynamic url so that when you deploy your app to server,then you get no error(s)
action="{{ url('/register') }}

Change the type of the button:
<button type="submit"

Related

Laravel | Form not submitting to route given in action [SOLVED]

I'm trying to submit a form to the right route using the action:
<form action="{{ route('document.destroy', $d->id) }}" method="POST" style="display: inline;">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<span type="text" value="" class="btn btn-success" readonly="readonly">
{{ $d->file_name }} ({{ $d->file_size }}) <i class="fa fa-times"></i>
</span>
<button class="btn btn-xs btn-default" type="submit" data-toggle="tooltip" title="Verwijder" onclick="return confirm('Weet je zeker dat je dit document wilt verwijderen')"><i class="fa fa-times"></i></button>
</form>
But yet it links to a different controller. What am I doing wrong?
I also specified the controller in the routes file:
Route::resource('document', 'DocumentController');
To add more context: this view gets passed from a different controller than I want to use for the DELETE function.
EDIT
I used a form inside another form, my stupid head didn't see it.
for deleting you can try this
<form action="{{action('DocumentController#destroy', $d->id)}}" method="post">
{{csrf_field()}}
<input name="_method" type="hidden" value="DELETE">
<button class="btn btn-danger" type="submit">Delete</button>
</form>
and Destroy method
public function destroy($id)
{
$doc= Document::find($id);
$doc->delete();
return redirect('/home')->with('success', 'Document has been deleted!!');
}

unable to submit form tag in laravel

unable to call post URL from form tag. When I click on the submit button it is going to a different URL name viewstudentmarks.
<form method="post" style="padding-top:30px;" action="{{ route('updatestudentmark',['id' => $stuid]) }}">
{{csrf_field()}}
<input type="hidden" name="type" value="{{$examtype}}">
<div class="row text-center">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="row">
<div class="col-lg-12">
<div class="form-group">
</div>
</div>
</div>
</div>
</div>
#foreach($extra as $detail)
<a class="btn btn-success" href='{{ url("viewstudentmarks/{$detail->class_id}") }}'>Back</a>
#endforeach
<input type="submit" class="btn btn-primary">
</form>
and web.php
Route::post('updatestudentmark/{id}','MarksRecordController#update')->name('updatestudentmark');
Route::get('viewhealthdetails/{id}','HealthDetailsController#viewstudents')->name('viewhealthdetails');
In form tag add {{ route('') }} name:
<form method="post" style="padding-top:30px;" action="{{ route('updatestudentmark',['id' => $stuid]) }}">
{{csrf_field()}}
</form>
Also, check your controller code. In the controller, Have you call the redirect method or not.
Thanks
it's much better to use name routes like:
Route::post('updatestudentmark/{id}','MarksRecordController#update')->name('test.route');
and in blade do something like this in action form:
{{route('test.route',['id' => $stuid])}}

laravel Route::resource not working for delete

Laravel Route::resource('countries', 'CountriesController'); now working for DELETE
Working only as (separately)Route::delete('/countries/{country}/delete', 'CountriesController#destroy');
<div class="row">
<div class="col-12">
<h1>Details for {{ $country->countryName }}</h1>
<p>Edit</p>
<form action="/countries/{{ $country->id }}/delete" method="post">
<input name="_method" type="hidden" value="DELETE">
#method('DELETE')
#csrf
<button type="submit" class="btn btn-danger">Delete1</button>
</form>
</div>
</div>
not working, I'm stuck at url:
http://192.168.1.7:8000/countries/6/delete
saying '404|not found'
You don't need to append /delete in the URL.
Try this:
<form action="/countries/{{ $country->id }}" method="post">
#method('DELETE')
#csrf
<button type="submit" class="btn btn-danger">Delete1</button>
</form>
As mentioned by #nakov, you can also remove the hidden input field. The blade directive #method('DELETE') is sufficient to do the job.
Hope it helps!

Laravel 5.4 CRUD DELETE Method not working, there is no reaction on clicking DELETE

After clicking on DELETE, there is no reaction, absolutely nothing happens. I am using HTML Forms, that's why I used, #method('DELETE'). I had similar problem with edit, after using #method(PUT), edit is working properly.
<div class="row">
<div class="col-6 align-self-start">
<a class="btn btn-light" href="/listings/{{$listing->id}}/edit">Edit</a>
</div>
<div class="col-6 align-self-end">
<form action="{{action('ListingsController#destroy', [$listing->id])}}" method="POST">
<?= csrf_field()?>
#method('DELETE')
<a class="btn btn-danger" href="/dashboard">Delete</a>
</form>
</div>
</div>
Destroy Function:
public function destroy($id)
{
$listing = Listing::find($id);
$listing->delete();
return redirect('/dashboard')->with('success', 'Contact Deleted');
}
Change
<a class="btn btn-danger" href="/dashboard">Delete</a>
to
<a type="submit" class="btn btn-danger" href="/dashboard">Delete</a>
You should add submit otherwise it will not submit the form.
Its recommended to use a instead of :
<button type="submit" class="btn btn-danger">Delete</button>

laravel delete method not working

I've made a small laravel project but the delete method is nog working:
I use a resource controller
my route is :
Route::resource('roles','Admin\RoleController');
in my view I have
<form action="{{route('roles.destroy',$role->id)}}" style="display:inline">
#method('delete')
#csrf
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
But when i click the button it will show me the role ( = get method of the resource )
What am I doing wrong ?
If you're using Laravel 5.1 or later
<form action="{{ route('roles.destroy', 'YOUR_ID') }}" method="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
If you're using Laravel 5.6 or later
<form action="{{ route('roles.destroy', 'YOUR_ID') }}" method="POST">
#method('DELETE')
#csrf
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
You can read more about method spoofing in Laravel Documentation.
Check Laravel's documentation.
Did you try adding method="POST" to the form?

Resources