Reputation: 541
I have been making forms in Laravel as part of a blog tutorial on youtube: https://www.youtube.com/watch?v=kmCtXryFwDc. I am using Laravel 5.3 and Firefox. Ive created a form that is supposed to submit an update that will update a post on the blog site. When I click the submit button, nothing happens in my browser. It behaves no differently that if my submit button only had the css applied to it and no other attributes or anchor tags.
Am I forgetting something simple here or is there something weird with the new version of Firefox which I just switched over to?
posts/update.blade.php:
@extends('main')
@section('title', '| Edit Post')
@section('stylesheets')
<link href="{{ secure_asset('css/parsley.css') }}" rel="stylesheet">
@endsection
@section('content')
<div class="form" method="POST" action="{{ route('posts.update', $post->id) }}">
<div class="row">
<div class="col-12 col-md-8">
<input type="text" class="form-control" name="title" value="{{ $post->title }}"/>
<hr>
<textarea class="form-control" name="body" rows="10">{{ $post->body }}</textarea>
</div>
<div class="col-12 col-md-4">
<div class="card border-light text-center">
<div class="card-header"><strong>Post Info</strong></div>
<div class="card-body">
<dl class="row end">
<dt class="col-4">Created:</dt>
<dd class="col-8">{{ date('M j, Y g:i', strtotime($post->created_at)) }}</dd>
<dt class="col-4">Updated:</dt>
<dd class="col-8">{{ date('M j, Y g:i', strtotime($post->updated_at)) }}</dd>
</dl>
<hr>
<div class="row">
<div class="col-12 col-sm-6">
<button type="submit" class="btn btn-success btn-block">Update</button>
</div>
<div class="col-12 col-sm-6">
<a href="{{ route('posts.destroy', $post->id) }}" class="btn btn-info btn-block">Cancel</a>
</div>
{{ Form::token() }}
{{ method_field('PUT') }} <!-- generates hidden field that sets the form method to PUT because HTML5 doesn't support it -->
</div>
</div>
</div>
</div>
</div>
</div>
@stop
@section('scripts')
<script src="{{ secure_asset('js/parsley.min.js') }}"></script>
@stop
Upvotes: 1
Views: 2448
Reputation:
<div class="form" method="POST" action="{{ route('posts.update', $post->id) }}">
change this as below
<form class="form" method="PUT" action="{{ route('posts.update', $post->id) }}">
if this is a form, must be start as form tag.
Also in laravel framework, you can use laravel collective forms. Here is docs
Upvotes: 0
Reputation: 51
Form tag is missing in your code plesae take a look
<div class="form" method="POST" action="{{ route('posts.update', $post->id) }}">
to
<form class="form" method="POST" action="{{ route('posts.update', $post->id) }}">
And close the form tag as well.
Also you can use
{{ Form::open(array('url' => 'foo/bar')) }}
//
{{ Form::close() }}
Upvotes: 2