dsaff82024 2016-01-27 11:31
浏览 127
已采纳

使用PHP cURL提交表单,多个具有相同名称的复选框

I am trying to submit an external form using PHP cURL. All form fields are working fine, except a problem I have with multiple checkboxes with the same name.

<input type="checkbox" name="same_name" value="value_1">
<input type="checkbox" name="same_name" value="value_2">
<input type="checkbox" name="same_name" value="value_3">

I have no problem with passing ONE of the checkboxes in the cURL request. In my POST string, I just do:

curl_setopt($ch, CURLOPT_POSTFIELDS, '...&same_name=value_1');

But now, I want to submit the form with multiple boxes checked. I tried the suggestion in the comments on this StackOverflow post:

curl_setopt($ch, CURLOPT_POSTFIELDS, '...&same_name[]=value_1&same_name[]=value_2');

But then I get a response which is based on no checked checkboxes at all, ergo it doesn't work.

Basically, how can I submit such an array correctly in this request? Who can point me in the right direction?

  • 写回答

3条回答 默认 最新

  • doulun1915 2016-01-27 12:06
    关注

    Hmm, it's really weird. I just tried to setup my own page (this one is external) with the following code, and it indeed seemed impossible to select more than one value:

    <form method="post">
     <input type="checkbox" name="same_name" value="1">Value 1<br />
     <input type="checkbox" name="same_name" value="2">Value 2<br />
     <input type="checkbox" name="same_name" value="3">Value 3<br />
     <input type="submit">
    </form>
    <?php
    if(isset($_POST))
    {
     print_r($_POST);
    }
    ?>
    

    But after some tweaking, I think I got it working anyhow with ..&same_name=value_1&same_name=value_2.

    I don't know HOW they do it on their serverside, but it appears to work!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch