doom910730 2018-09-05 09:44
浏览 221

如何使用一个提交按钮传递多个表单数据

I am trying to post forms with multilanguages. For example i have en, es, ru language. I need to save en to the one table. Es and ru forms are must save into the translations table. But i can't pass the all datas to the controller@store function. How can i pass all datas with separatedly to the controller?

I am passing languages with compact. Like that:

public function index()
{
    $langs = [];
    foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
    {
        $langs[]= $localeCode;
    }

    return view('backEnd.langview', compact('langs'));
}

In the view i have tab panel for each language. This is the view:

@foreach(LaravelLocalization::getSupportedLocales() as $localeCode => $properties)
@if($loop->first)
    <div class="tab-pane animated fadeIn text-muted active" id="tab{{$localeCode}}" aria-expanded="false">{{$localeCode}}
        <form method="POST" id="form{{$localeCode}}" action="{{route('send_slug')}}">
        {{csrf_field()}}
            <input type="text" name="main_title" placeholder="title here">
            <input type="text" name="main_slug" placeholder="slug here">
        </form>
    </div>
@else
    <div class="tab-pane animated fadeIn text-muted" id="tab{{$localeCode}}" aria-expanded="false">{{$localeCode}}
    <form method="POST" id="form{{$localeCode}}" action="{{route('send_slug')}}">
    {{csrf_field()}}
        <input type="text" name="title[]" placeholder="title here other languages">
        <input type="text" name="slug[]" placeholder="slug here other languages">

    </form>
    </div>
@endif

@endforeach

I was tried that with ajax:

<script>
var langcodes = @json($langs);
var i = 0;
submitForms = function(){
    langcodes.forEach(function (data) {
        i++;
        var formdata = $('#form'+data).serialize();
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
            }
        });
        jQuery.ajax({
            url: '{{route('send_slug')}}',
            method: 'post',
            data: {
                formdata
            }
        });
    });
}

But every try, i just can pass first language, or last language. I need to send all languages with separatedly. I hope i can express myself. Sorry about my language. Thanks in advance.

  • 写回答

4条回答 默认 最新

  • duande1985 2018-09-05 09:52
    关注

    try this for pass multiple form data in ajax

    var formdata = $("#form1, #form1").serialize();
    
    评论

报告相同问题?

悬赏问题

  • ¥50 comsol稳态求解器 找不到解,奇异矩阵有1个空方程返回的解不收敛。没有返回所有参数步长;pid控制
  • ¥15 怎么让wx群机器人发送音乐
  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功