dongyunshan4066 2018-02-09 18:01
浏览 55
已采纳

如何正确构建这个多步形式?

I have a page create_conference.blade.php to create new confereces. In this page there is a multi step form:

  • in the 1st step asks the user for general conference information
  • in the 2nd asks for a description for the conference creator
  • in the 3rd aks the user for the registration types for the conference

The way the form should work is: the user enter the information for the first step then click “go to step 2”, then in step 2, the user enters that step 2 specific information and click “go to step 3”. Finally, in step 3, the user enter that step 3 specific information and also clicks in “Store” to submit the information and so the conference is created.

Do you know how to properly handle this multi step form logic with laravel? Im not having success in structuring this.

HTML:

<!-- So, the page has 3 step: General Info, Conference Creator Info and Registration Types) -->
    @extends('app')
    @section('content')
            <div class="container nopadding py-4">
                <h1 class="h5 text-center">Create Conference</h1>
                <div class="row">
                    <div class="col-12">
                            <ul class="nav nav-pills registration_form_list" role="tablist">
                                <li class="">
                                    <a class="nav-link active" href="#step1" data-toggle="tab" role="tab">
                                        Step1<br><small>General Information</small></a>
                                </li>
                                <li class="disabled">
                                    <a class="nav-link" href="#step2" data-toggle="tab" role="tab">
                                        Step 2<br><small>Conference Creator Info</small></a>
                                </li>
                                <li class="disabled">
                                    <a class="nav-link" href="#step3" data-toggle="tab" role="tab">
                                        Step 3<br><small>Registration Types</small></a>
                                </li>
                            </ul>

                    <!-- STEP 1 - General Confenrece Information-->

                    <form method="post" class="clearfix" action="conference/store">
                    {{csrc_field()}}
                        <div class="tab-content registration_body bg-white" id="myTabContent">
                            <div class="tab-pane fade show active clearfix" id="step1" role="tabpanel" aria-labelledby="home-tab">
                                <form method="post" class="clearfix">
                                    <div class="form-group">
                                        <label for="conference_name" class="text-heading h6 font-weight-semi-bold">Conference Name </label>
                                        <input type="text" name="conference_name" class="form-control" id="conference_name">
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col-lg-6">
                                            <label for="conference_categories" class="text-heading h6 font-weight-semi-bold">Conference Categories</label>
                                            <select id="tag_list" name="conference_categories" multiple class="form-control" id="conference_categories">
                                                <option>IT</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label for="address" class="text-heading h6 font-weight-semi-bold">Address</label>
                                            <input type="text" name="conference_address" class="form-control" >
                                    </div>
                                    <div>

                                        <button type="button" href="#step2" data-toggle="tab" role="tab"
                                                class="btn mr-2 btn-primary btn next-step">
                                            Go To Step 2
                                        </button>
                                    </div>
                                </form>
                            </div>

                    <!-- STEP 2 - Conference creator Information-->

                            <div class="tab-pane fade clearfix" id="step2" role="tabpanel" aria-labelledby="profile-tab">
                                <form method="post" class="clearfix">
                                    <div class="form-row">
                                    <div class="form-group">
                                        <label for="conference_creator_description" class="text-heading h6 font-weight-semi-bold">Description</label>
                                        <textarea name="conference_creator_description" id="conference_creator_description" class="form-control" rows="3"></textarea>
                                    </div>

                                       <button type="button" href="#step1" data-toggle="tab" role="tab"
                                                class="btn mr-2 btn-primary btn next-step">
                                            Go Back To Step 1
                                        </button>
                                       <button type="button" href="#step3" data-toggle="tab" role="tab"
                                                class="btn mr-2 btn-primary btn next-step">
                                            Go To Step 3
                                        </button>
                                </form>
                            </div>

                    <!-- STEP 3 - Registration Types-->

                            <div class="tab-pane clearfix fade" id="step3" role="tabpanel" aria-labelledby="contact-tab">
                                <form method="post" class="clearfix">
                                    <div class="form-group">
                                        <label for="registration_type_name" class="text-heading h6 font-weight-semi-bold">Registration Type Name</label>
                                        <input type="text" name="registration_type_name" class="form-control" id="registration_type_name">
                                    </div>

                                    <div class="form-group col-md-6">
                                        <label for="registration_type_capacity" class="text-heading h6 font-weight-semi-bold">Capacity</label>
                                        <input type="text" class="form-control" name="registration_type_name" id="registration_type_capacity">
                                    </div>
                                      <div class="form-group">

                                             <button type="button" href="#step2" data-toggle="tab" role="tab"
                                                class="btn mr-2 btn-primary btn next-step">
                                            Go Back To Step 2
                                        </button>
                                       <button type="submit"  data-toggle="tab" role="tab"
                                                class="btn mr-2 btn-primary btn next-step">
                                            Store
                                        </button>
                                    </div>
                                </form>
                            </div>        
                        </div>
                    </form>
                </div>
            </div>
        </div>

Laravel:

  • I created a ConferenceController
  • Then add to the form an action (action="conference/store")
  • Then I also created a route:

    Route::post(‘/createConference, [ ‘uses’ => ‘ConferenceController@store’ ‘as’ => conference.store’ ]

But when I enter some info and submit the form it appears:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message.   
  • 写回答

1条回答 默认 最新

  • drfm55597 2018-02-09 19:10
    关注

    Wrong action url

    Route::post(‘/createConference,[‘uses’=>‘ConferenceController@store’,‘as’=>conference.store’]);
    

    Set form's action to route's name and add crsf field

    <form action="{{route('conference.store')}}" method="post">
    {{ csrf_field() }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 数学的三元一次方程求解
  • ¥20 iqoo11 如何下载安装工程模式
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题