javascript - form not being submitted laravel
I am building a basic form in laravel 5.4.22 but it is not being submitted, when i click on submit it stays on the same page just changing the url to something different I used this Route
Route::post('/contact/submit', '[email protected]');
This is the controller i made use of
`<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class MessagesController extends Controller
{
public function submit(Request $request){
this->validate($request, [
'name' => 'required',
'email' =>'required'
]);
return 'SUCCESS';
}
}; `
& here is my contact form
@extends('layouts.app')
@section('content')
<H1>Contact</H1>
{!! Form::open(['action'=>'[email protected]','method'=>'post']) !!}
<div >
{{Form::label('name', 'Name')}}
{{Form::text('name', '', ['class' => 'awesome form-control', 'placeholder' => 'Enter name'] )}}
</div>
<div >
{{Form::label('email', 'E-Mail Address')}}
{{Form::text('email', '', ['class' => 'awesome form-control', 'placeholder' => 'Enter Email id'])}}
</div>
<div >
{{Form::label('messages', 'Message')}}
{{Form::textarea('message', '', ['class' => 'form-control', 'placeholder' => 'Enter your message here'])}}
</div>
<div>
{{Form::submit('Submit', ['class'=> 'btn btn-primary'])}}
</div>
{!! Form::close() !!}
@endsection
,This is the main page where i connect the other things
<!DOCTYPE html>
<html>
<head>
<title>Dradz</title>
<link rel="stylesheet" type="text/css" href="/css/app.css">
</head>
<body>
@include('inc.navbar')
<div >
@if(Request::is('/'))
@include('inc.showcase')
@endif
<div >
<div >
@include('inc.messages')
@yield('content')
</div>
<div >
@include('inc.sidebar')
@show
</div>
</div>
</div>
<footer id="footer" >
<p>Copyright 2017 © Dradz</p>
</footer>
</body>
</html>
Answer
Solution:
Try to add slash to the beginnig of the url and set method to 'POST'
Also I would recommend you to give names for all your routes like:
and then you can use it in your form:
Answer
Solution:
First, always use REQUEST file for validation it's best practice by far . Second instead of this :
use something like :