【问题标题】:How to populate a form in POST method如何在 POST 方法中填充表单
【发布时间】:2017-05-24 16:25:49
【问题描述】:

我在网站上有一个表单,我需要手动提交数百条记录。表单是 POST 方法。

我尝试了简单的:http://.../form?incomingLead__email=MYNAME。但这不起作用。

如何操作表单提交操作以包含值?

尝试使用如下单个字段:这是 HTML 中的 First Name 属性:

<input id="incomingLead__firstName" name="incomingLead__firstName" 
class="text" style="" type="text" onkeypress="var _this=this;return 
onEnterPressed(event, function()
{document.controller.setValue('/ctx/incomingLead/@firstName',
_this.value, 'incomingLead__firstName');return true;});" 
onblur="document.controller.setValue('/ctx/incomingLead/@firstName', 
this.value, 'incomingLead__firstName')">

表单属性为:

<form method="post" name="page" class="main-navigation" id="page-form">

提交按钮:

<button type="button" id="link-link330" onclick="return linklink330();">Submit</button>

验证 JS 函数:

function toValidate() {
  var temp = document.getElementById('temp')
  if (!temp) return document.controller.submit('submit');

  document.controller.setValue("/ctx/vars/iCountProducts", temp.options.length);


  for (var i = 0; i < temp.options.length; i++)
    document.controller.setValue("/ctx/vars/products/product" + i, temp.options[i].value);

  return document.controller.submit('submit');
}

我想有一个excel文件,把我需要的链接串起来,至少我可以减少填表数据的时间,变成2次点击:在excel中打开webform,然后提交。

根据给定的数据可以吗?

【问题讨论】:

  • 为什么要手动?如果您在 excel 文件中有数百条记录,您可以将整个事情自动化。
  • 我尝试上传到的系统不属于我。寻找替代品。
  • 更有理由让它自动化。看我的回答。

标签: forms


【解决方案1】:

仅当您尝试上传到的系统提供此类功能时,才可以填充表单。 即使是这样,离真正的手动数据输入也只有一步之遥,所以我建议避免使用它。 数百条记录需要很长时间。

如果您的数据源是 excel 文件,您可以自动化整个上传过程。 只需读取excel文件,将相关行一一处理,为每一行发送一个POST请求。

以下是 PHP 中的示例实现:

//open xlsx file
$simple = new SimpleXLSX('power-mosfet.xlsx');

//get rows from the first worksheet
$rows = $simple->rows(1);

//process specific lines (starts from 0)
$fromLine = 2;
$toLine = 8;
for($i = $fromLine; $i<$toLine; $i++){
    //select relevant values
    $data = [
        'name'  => $rows[$i][0], //column 1
        'vdss'  => $rows[$i][1], //column 2
        'rdson' => $rows[$i][2], //column 3
    ];

    //send the data in a post request
    $ch = curl_init('http://example.com/form');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_exec($ch);
    curl_close($ch);
}

如果 PHP 不在您的驾驶室中,只需使用一种编程语言即可。 概念是一样的。

【讨论】:

    【解决方案2】:

    您可以编写一个浏览器扩展来处理数据导入、表单字段水合以及最终的提交;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-14
      • 2018-06-13
      • 1970-01-01
      • 1970-01-01
      • 2023-02-02
      • 1970-01-01
      • 2021-01-01
      • 2014-01-02
      相关资源
      最近更新 更多