dsaj20411 2017-06-07 14:10
浏览 13
已采纳

Laravel表单不发送动态生成内容的请求

I have a form like this:

<form class="form-horizontal" role="form" method="POST" name="myform" id="myform" action="{{ url('/mypage/') }}">
        {{ csrf_field() }}
<div id="somecontent">
</div>
<div id="abutton">
</div>
</form>

Then some Jquery like this:

 $('#somecontent').html('<select class="form-control" id="myselect"  form="my"><option value="1">Hello</option><option value="2">World</option></select>');

And then I add a button like this:

button = $('<button type="submit" form="myform" class="btn btn-theme">Send</button>');

$('#abutton').html(button);

And I also change the action dynamically:

 $("#myform").attr("action","/mypage/" + item_id);

Then I got this in the web file:

Route::post('/mypage/{item_id}','mycontroller@do_something');

And then do this in the controller:

public function do_something($item_id,Request $request){
dd($request);
}

But the $request is empty, it does not contain the value selected in the dynamically generated select.

Any ideas why?

  • 写回答

1条回答 默认 最新

  • donglu3243 2017-06-07 14:30
    关注

    you haven't added name attribute of select, add name attribute and see it will populate into $request.

    Try below code.

     $('#somecontent').html('<select name="select_name" class="form-control" id="myselect"  form="my"><option value="1">Hello</option><option value="2">World</option></select>');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化