好吧,我的表格有点问题,我试过很多方法都没用 当我点击SEND时,它会给我这个错误
TokenMismatchException in VerifyCsrfToken.php line 53:
好的,我得到了这个,我把<input type="hidden" name="_token" value="{{ csrf_token() }}">
然后我收到了这个错误
<form action="" method="post" class="landing-form">
这是我的表单代码
MethodNotAllowedHttpException in RouteCollection.php line 219:
这也是我的class.FormValidation.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>landin page</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script type="text/javascript" href="{{asset('js/class.FormValidation.js')}}"></script>
<script type="text/javascript" href="{{asset('js/landin_validation.js')}}"></script>
<link rel="stylesheet" type="text/css" href="{{asset ('js/style.css')}}"/>
</head>
<body>
<div class="page-wrapper">
<div class="header-wrapper">
<div class="header-content">Company Logo Here</div>
</div>
<div class="content">
<h1>Advertising Header Goes Here!</h1>
<p>
There are many variations of passages of Lorem Ipsum available,<br/>
but the majority have suffered alteration in some form, by injected humour, <br/>
or randomised words which don't look even slightly believable. <br/>
If you are going to use a passage of Lorem Ipsum, <br/>
you need to be sure there isn't anything embarrassing hidden in the middle of text. <br/>
All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, <br/>
making this the first true generator on the Internet. It uses a dictionary of over 200 Latin words, <br/>
combined with a handful of model sentence structures, to generate Lorem Ipsum which looks reasonable. <br/>
The generated Lorem Ipsum is therefore always free from repetition, injected humour,<br/>
or non-characteristic words etc.
</p>
<div class="form-wrapper">
<form action="" method="post" class="landing-form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<label>Fill your details here - </label><br/><br/>
<input placeholder="Full name:" type="text" name="name" class="field-name" />
<input placeholder="Email:" type="text" name="email" class="field-email" />
<input placeholder="Phone Number:" type="text" name="phone" class="field-phone" />
<input type="submit" name="submit" value="Send" />
</form>
</div>
</div>
<div class="footer">2014 © My Compay Name</div>
</div>
</body>
</html>
这是路线:
function FormValidation(){
this.nameReg = [
/^([a-zA-Z\s]+){2,255}$/
];
this.emailReg = [
/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
];
this.phoneReg = [
/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/i,
/^[0-9]{3}.[0-9]{3}.[0-9]{4}$/i,
/^\([0-9]{3}\)-[0-9]{3}-[0-9]{4}$/i,
/^[0-9]{9,10}$/i
];
this.testName = function( nameInput ){
return this.inputCheck(this.nameReg, nameInput);
};
this.testEmail = function( emailInput ){
return this.inputCheck(this.emailReg, emailInput);
};
this.testPhone = function( phoneInput ){
return this.inputCheck(this.phoneReg, phoneInput);
};
this.inputCheck = function( regArray, inputData ){
var valid = false;
$.each( regArray, function( key, val ){
if( val.test( inputData ) ){
valid = true;
}
});
return valid;
};
}
这是pagescontroller:
Route::get('contact', 'PagesController@contact');
我真的希望你帮助我,谢谢:)。
答案 0 :(得分:1)
看起来您的联系路线的POST请求没有可用的路由。正如你所说:
Route::get('contact', 'PagesController@contact');
是您表单的路由,但Laravel无法使用您从表单发送的POST请求验证GET请求。因此,您需要第二个路径(和方法)来处理POST请求:
Route::post('contact', 'PagesController@postContact');
你仍然需要在PagesController上使用postContact()方法来处理post请求。
P.S。你也可以用这个:
{!! csrf_field() !!}
这会将令牌字段的HTML代码添加到表单中,而无需键入任何隐藏字段。
P.S。你也可以用这个:
Route::any('/contact', 'PagesController@contact');
但是这需要你在contact()方法中执行逻辑(从GET请求中分离POST)。