成功提交表单后,我应该会在这里看到'在浏览器中但我被重定向到找不到的页面视图:
抱歉,找不到您要查找的页面。
我的表单控件:
{!! Form::open(['url' => 'prize_draw_store', 'class' => 'wffm-form-module text-left']) !!}
{!! Form::label('fullname', 'Name:', array('class' => 'control-label')) !!}
{!! Form::text('fullname', null, array('required', 'class'=>'form-control text-box single-line', 'placeholder'=>'')) !!}
{!! Form::label('email_address', 'Email Address:', array('class' => 'control-label')) !!}
{!! Form::text('email_address', null, array('required', 'class'=>'form-control text-box single-line', 'placeholder'=>'')) !!}
<div class="form-submit-border">
{{ Form::submit('Submit', array('class' => 'btn btn-default')) }}
</div>
{!! Form::close() !!}
我的路线定义明确:
/routes/web.php
use App\Http\Controllers\PrizeDrawController;
use App\Http\Requests\PrizeDrawFormRequest;
Route::get('/',
['as' => 'prize_draw', 'uses' => 'PrizeDrawController@create']);
Route::post('/',
['as' => 'prize_draw_store', 'uses' => 'PrizeDrawController@store']);
PrizeDrawController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\PrizeDrawFormRequest;
class PrizeDrawController extends Controller
{
public function create() {
return view('front.pages.home');
}
public function store(PrizeDrawFormRequest $request) {
var_dump('in here');
return redirect('thankyou')->with('status', 'Form submitted!');
}
}
PrizeDrawFormRequest.php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class PrizeDrawFormRequest extends FormRequest
{
public function authorize()
{
return true;
}
public function rules()
{
return [
'email_address' => 'required|email',
'fullname' => 'required'
];
}
}
我希望代码像这样流动:
1. http://aacomp.local/prize_draw_store -- POST form submission
2. App\Http\Controllers\PrizeDrawController@store
3. PrizeDrawController::store(PrizeDrawFormRequest $request)
4. Redirect a user to thankyou page
我们似乎没有达到第3步?我必须遗漏一些基本的东西 - 你能帮忙吗?
提前致谢。
答案 0 :(得分:1)
问题在于:
Route::post('/',
['as' => 'prize_draw_store', 'uses' => 'PrizeDrawController@store']);
将此路线更改为
Route::post('/foobar',
['as' => 'prize_draw_store', 'uses' => 'PrizeDrawController@store']);
并更新表单操作:
{!! Form::open(['url' => 'foobar', ...
说 - 会得到理想的结果。感谢大流士。 V为此。