我需要验证已存在的天气的电子邮件ID
我已经尝试过这段代码,但它无法正常工作,并在inspect元素中显示:
的jquery-1.10.2.js:8706
POST http://localhost/selfcomply/public/admin/companymaster/check_email.php 405(方法不允许)和
RouteCollection.php第218行中的MethodNotAllowedHttpException:
validation.js文件
$("#companydata").validate
({
rules: {
company_email:{
required: true,
emailer: true,
remote:{
url:"check_email.php",
type:"post"
}
},
messages:{
company_email:{
required: "Please enter the email address ",
remote:"Already Exist"
},
}
});
check_email.php
$email = "'".$_POST["emails"]."'";
$showmember = DB::select( DB::raw("SELECT count(company_email) as countemail FROM tbl_company_master WHERE company_email = ".$email.""));
if($showmember[0]->countemail > 0)
{
return "false";
}
else
{
return "true";
}
天气我需要在route.php中给出路径,但我不这么认为
答案 0 :(得分:0)
如果你使用laravel,而不是改变:
url:"check_email.php", // This is the core php way of passing the file name here
到
url: "/checkemail", // In laravel, you have to pass a route here
为此,您必须在以下路线中定义get
路线:
Route::get('/checkemail', 'MyController@myFunction');
此处myFunction
是MyController
中定义的函数,它根据电子邮件检查逻辑返回true/false
。
答案 1 :(得分:0)
您可以检查查询中是否存在电子邮件(由Eloquent ORM提供支持):
在此处更改:
remote:{
url:"checkEmail",
type:"post"
}
并且还改变了route.php,
Route::post('/checkEmail', 'MyController@checkEmailvalid');
比php控制器
public function checkEmailvalid()
{
$user = User::all()->where('email', Input::get('email'))->first();
if ($user) {
return Response::json(Input::get('email').' is already taken');
} else {
return Response::json(Input::get('email').' Username is available');
}
}