简体   繁体   中英

Laravel multiple forms with a only one submit button?

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??

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM