Laravel Bootstrap Modal Submit按钮不起作用

时间:2018-08-27 14:04:52

标签: laravel bootstrap-4 bootstrap-modal laravel-5.5

我很疯狂,试图创建一个模式窗口将控件返回到我的视图。按钮类型为“提交”,但不会启动路线。我看过一些教程,在那里,我要做的全部工作就是将动作定义为路线并具有一个提交按钮。我已经看到了,不需要ajax,或者我不知道他们何时编写代码...我去了w3c,在“亲自尝试”中,我汇总了提交按钮,实际上该窗口没有关闭。所以我完全被困住了,将不胜感激。

部分观点

    <main role="main" class="col-md-9 ml-sm-auto col-lg-10 pt-3 px-4">
      <div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 border-bottom">
        <h1 class="h5">Horarios</h1>
        <div class="btn-toolbar mb-2 mb-md-0">
          <div class="btn-group mr-2">
            <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#create-horario">+</button>

            <div class="modal fade" id="create-horario" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" >
              <div class="modal-dialog" role="document">
                <div class="modal-content">
                  <div class="modal-header">
                    <h5 class="modal-title" id="ModalLabel">Nuevo horario</h5>                      
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                      <span aria-hidden="true">&times;</span>
                    </button>


                  </div>

                  <form action="{{ route('horarioperiodicos.store')}}" method="post">
         <!--           {{ method_field('patch')}} -->
                    {{ csrf_field() }}

                    <div class="modal-body">


                      <div class="form-group">
                        <label for="diaSemana" class="col-form-label">Día de la semana</label>
                        <select name="diaSemana" class="form-control">
                          <option value="1"  selected> Lunes</option>
                          <option value="2"  > Martes</option>
                          <option value="3"  > Miércoles</option>
                          <option value="4"  > Jueves</option>
                          <option value="5"  > Viernes</option>
                          <option value="6"  > Sábado</option>
                          <option value="7"  > Domingo</option>
                          </select> 
                      </div>


                      <div class="form-group">
                        <div style="width:50%;float:left;display:inline-block;">
                          <label for="HoraInicio" class="col-form-label">Hora de inicio</label>
                          <input type="time" id="HoraInicio" name="HoraInicio" min="9:00" max="18:00" value="09:00" >
                        </div>
                        <div align="right">
                          <label for="HoraFin" class="col-form-label">Hora de fin</label>
                          <input type="time" id="HoraFin" name="HoraFin" min="9:00" max="18:00" value="10:00">
                        </div>
                      </div>


                    </div>
                   </form>

                  <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
                    <button type="submit" class="btn btn-primary" id="submitForm">Guardar</button>
                  </div>
                </div>
              </div>
            </div>  



          </div>
        </div>
      </div>



    <table class="table">
      <thead class="thead-light">
        <tr>
          <th>Día</th>
          <th>Hora de inicio</th>
          <th>Hora de fin</th>        
          <th>Cambios</th>
       </tr>
      </thead>
      <tbody>

        @foreach($horarioPeriodicos as $horario)
          <tr>
            <td>  

              @switch( $horario->intDia )
                  @case( 1 )
                      Lunes
                    @break
                  @case( 2 )
                      Martes
                  @case( 3 )
                      Miércoles
                    @break
                  @case( 4 )
                      Jueves
                  @case( 5 )
                      Viernes
                  @case( 6 )
                      Sábado
                  @default
                      Domingo
                    @break
              @endswitch

            </td>
            <td> {{ $horario->timHoraInicio }} </td>
            <td> {{ $horario->timHoraFin }} </td>
            <td>
              <button class="btn btn-sm btn-outline-secondary">-</button> / 
              <button class="btn btn-sm btn-outline-secondary">Editar</button>
            </td>
          </tr>
        @endforeach


      </tbody>
    </table>




    </main>

HorarioPeriodicosController(不要进入它,在我的角色列表中)

public function store(Request $request)
{
    //
    dd(1);
}

My routes list

我试图对此进行修改

                  <form action="{{ route('horarioperiodicos.store')}}" method="post">
                    {{ method_field('patch')}} 

为此

                  <form action="{{ route('horarioperiodicos.store')}}" >

等,等等。

罕见的是,即使我在那里进行更改,也不会启动错误。

非常感谢

1 个答案:

答案 0 :(得分:2)

您需要将<button>元素的<form> 放入

否则,将不会触发表单提交。

或者您可以将按钮放置在表单外部,但是您需要在按钮元素中包含与表单的form=属性相对应的id=属性:< / p>

<form id="myform" method="post" action="{{ route('store.create') }}">
    <input type="text" name="name" />
</form>

<input type="submit" form="myform" />