duandai2178 2016-06-26 23:33
浏览 23

Laravel多个表单只有一个提交按钮?

I have a form that can edit multiple areas in multiple tables, but it does not work unless I have a submit button within each form , is there any way to do this with one submit button?

    {!!Form::model($pregunta,['route'=>['seleccion.update',$pregunta->id],'method'=>'PUT','files' => true])!!}
    {!!Form::label('categoria','Categoria: ')!!}
      {!!Form::select('categorias_id', $categoria,null,['id'=>'categoriaSelSimple','class'=>'form-control',
                                            'placeholder'=>'Seleccione una opcion..','required'])!!}<br>
      {!!Form::label('subcategoria','Sub-categoria: ')!!}
      {!!Form::select('sub_categorias_id', $subcategoria,null,['id'=>'subcategoriaSelSimple','class'=>'form-control',
                                            'placeholder'=>'Seleccione una opcion..','required'])!!}<br>
    @foreach($opcion as $key => $value)
        {!!Form::model($value,['route'=>['opciones.update',$value->id],'method'=>'PUT'])!!}
        <div class="form-group option-container">
            <div class="input-group ">
              @if($value->correcto == 1)
                <span class="input-group-addon">
                  {!!Form::select('correcto[]', ['0' => 'Incorrecto','1' => 'Correcto'])!!}
                </span>
              @else
                <span class="input-group-addon">
                  {!!Form::select('correcto[]', ['1' => 'Correcto','0' => 'Incorrecto'])!!}
                </span>
              @endif
                {!!Form::text('opcion[]',$value->opcion,['class'=>'form-control']) !!}
                {{-- {!!Form::text('opcion[]',null,['class'=>'form-control', 'placeholder'=>'Ingresa una opcion..'])!!} --}}
              <span opcion-id="{{$value->id}}" class="input-group-btn">
                  <button class="btn btn-outline btn-danger btn-remove" type="button">X</button>
              </span>
            </div>
        </div>
        {{Form::close()}}
      @endforeach
                        <button type="button" class="btn btn-outline btn-success btn-lg btn-block btn-add-more-options">Agregar opción</button>
                        <h1 class="page-header"></h1>
                        {!!Form::submit('Actualizar',['class'=>'btn btn-outline btn-primary'])!!}

        </div>

    <!-- /.col-lg-8 -->
    <!-- /.col-lg-4 -->
</div>
{!!Form::close()!!}

I have multiple forms, one main and the others added through a foreach (how many depends of the table ), so i need to update these fields generated by the foreach but it doesn't work because i dont have a submit button for each form, how i can do this??

  • 写回答

1条回答 默认 最新

  • dpt8910 2016-06-27 00:01
    关注

    Using only HTML, no, multiple forms cannot be submitted with a single submit button.

    This could be done using a bit of JavaScript. For each form you would need to track which values had been changed, then submit those forms via AJAX.

    Another thing to consider is combining all the forms into a single HTML form and let the controller->action() put the information where it belongs.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度