duanqiao2225 2017-09-04 12:55
浏览 41
已采纳

如果发送的数据包含多于表单,如何在php中检索表单字段

I have a simple form in which the user can enter a search term:

<form class="form-inline justify-content-center" id="searchForm">
      <div class="form-group">
            <label class="sr-only text-info" for="searchTerm">Search term</label>
            <input type="text" class="form-control mb-2 mr-sm-2 mb-sm-0" name="searchTerm" id="searchTerm" placeholder="Search">
       </div>
       <button type="submit" class="btn btn-info">Search</button>
</form>

And I send the form using ajax like this:

$form = $(e.target);
    $.ajax({
        url: "searchmovielist.php",
        type: "GET",
        data: {form: $form.serialize(), username: getCookie('username')},
        success: function (response) {
            console.log(response);
        }
    });

My question is how do I retrieve the fields from the form in php if I get the form using $_GET['form']?

  • 写回答

1条回答 默认 最新

  • dplbf4340 2017-09-04 14:16
    关注

    You can use PHP function parse_str to split the string to array. So the code would be like

    $username = $_GET['username']
    parse_str($_GET['form'], $form_data);
    var_dump($form_data);
    

    But I'm wondering why are you reading username from a cookie and then sending it again in the request? Why not just read it from $_COOKIE in PHP?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
  • ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
  • ¥15 MATLAB和mosek的求解问题
  • ¥20 修改中兴光猫sn的时候提示失败
  • ¥15 java大作业爬取网页
  • ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
  • ¥15 有没有办法利用libusb读取usb设备数据
  • ¥15 为什么openeluer里面按不了python3呢?
  • ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
  • ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!