【问题标题】:Fill input field without name and click div with PHP cURL?填写没有名称的输入字段并使用PHP cURL单击div?
【发布时间】:2020-09-03 15:07:45
【问题描述】:

我正在尝试使用 PHP cURL 在 url 上填写和提交表单,但是,他们没有使用带有提交按钮的常规 form 标签。相反,他们只有一个带有 onclick 的 div 来提交在 input 字段中输入的值,该字段没有 name,但确实有一个 id 和一个 onChange 事件。

您可以在here 中看到它。 (您可以搜索“5458-011”进行测试。)

如何在input 字段中输入值并通过 cURL 提交?

以下是该网址的代码。

HTML:

<input onChange="mirrorSearch2()" list="addresses2"class="Header-Search-field" id="addressInputSmall" placeholder="Search by address, parcel or planning application number, or click on the map"/>
<datalist id="addresses2"></datalist>
<div onclick="runSearch(document.getElementById('addressInputSmall').value,'','addressInputSmall')" class="fa fa-search fa-2x" aria-hidden="true" id="Search-icon2"></div>

Javascript / jQuery:

//onChange
function mirrorSearch2() {
    var thenew=$('#addressInputSmall').val()
    //console.log(thenew);
    $('#addressInput').val(thenew);
}
function mirrorSearch() {
    var thenew=$('#addressInput').val()
    //console.log(thenew);
    $('#addressInputSmall').val(thenew);
}

//onClick
function runSearch(theAddress,theType,theID) {
    //Now run a second query to get the geometry, if no geometry is found then send to old PIM search functionality (e.g. PPTS non-parcel records)
    //console.log("RunSearch: "+theAddress)

    if (theID=="addressInput") {
        //console.log($('#addresses').children().length)
        if  ($('#addresses').children().length==1  ) {
            //if there is only one option and they hit enter, then get the option value rather than search for the incomplete text.
            //e.g. if they typed 1650 miss and hit enter, then send the 1650 MISSION ST from the option list.
            $("#addresses").prop("selectedIndex", 0);
            if ($( "#addresses option:first" ).val()) {
                setTimeout('throttleSubmit($( "#addresses option:first" ).val());',400)
                return
                //theAddress = $( "#addresses option:first" ).val();
            }
        }
    }
    if (theID=="addressInputSmall") {
        //console.log($('#addresses2').children().length)
        if  ($('#addresses2').children().length==1  ) {
            //if there is only one option and they hit enter, then get the option value rather than search for the incomplete text.
            //e.g. if they typed 1650 miss and hit enter, then send the 1650 MISSION ST from the option list.
            $("#addresses2").prop("selectedIndex", 0);
            if ($( "#addresses2 option:first" ).val()) {
                setTimeout('throttleSubmit($( "#addresses2 option:first" ).val());',0)
                return
                //theAddress = $( "#addresses2 option:first" ).val();
            }
        }
    }
    //setTimeout('console.log($( "#addresses2 option:first" ).val())',100)
    //console.log(theAddress)
    throttleSubmit(theAddress)
}

【问题讨论】:

    标签: javascript php html jquery curl


    【解决方案1】:

    【讨论】:

    • 非常感谢,但是没有提交按钮我该如何提交呢?
    • 我的理解是,如果您使用 PHP cURL,则不需要提交按钮,您只需模仿他们网站的前端并将查询提交到他们的端点 sfplanninggis.org/arcgiswa/rest/services/Geocoder_V2/MapServer/… 使用 all必要的字段。但是,我不知道您是确切的用例,您可以提供更多信息。也许您只是想使用 HTML 并提交表单...
    • 用例是获取搜索生成的结果信息。那么,只需将搜索词提交到该端点就可以了吗?我实际上不需要让脚本点击div?
    • 好吧,如果您想使用 JS 触发和提交表单,只需执行 $('#Search-icon2').trigger('click');因为它在网站上有 jQuery 并且 div 有一个 ID,但使用 cURL 的重点是您可以直接从脚本生成 HTTP 请求并解析结果,而无需太多 JavaScript 使用。
    • 这里的主要目的是访问搜索完成后生成的“Assessor Recorded Documents”链接。您建议我做什么才能访问搜索后生成的文档?
    猜你喜欢
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 2012-08-28
    • 2016-03-11
    • 2013-03-24
    • 2016-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多