dongqian1028 2016-12-30 18:43
浏览 762
已采纳

将HTML参数传递给php页面

I am attempting to pass the parameters of the current html page to the php page using a form. So far I have the following function inside my header in the html

    <script>
    function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null;
}

    </script>

and then in the form I have the following

<input type="hidden" name="amtpaid" id="amtpaid" value="getURLParameter('amt')" />
        <input type="hidden" name="status" id="sts" value="getURLParameter('st')" />

this is assuming a url such like

www.somehost.com/page/?amt=5&sts=CONFIRMED

however all that the php says is posted is the following (this is aa dump of all post data)

Array ( [on1] => Steam 32 - ID (STEAM_0:X:XXXX) [os1] => hj [amtpaid] => getURLParameter('amt'); [status] => getURLParameter('st'); )

anyhelp??

  • 写回答

2条回答

  • douan0729 2016-12-30 18:51
    关注

    You're passing the literal string "getUrlParameter('amt')" as the value of the fields you are posting. You can't populate the "value" in this way. What you need to do is populate the values from javascript. Like this:

    document.getElementById("amtpaid").value = getUrlParameter('amt');
    document.getElementById("sts").value = getUrlParameter('st');
    

    This would need to be placed somewhere in a script tag in the page where it would be executed at a time that makes sense for your application, after those two hidden fields are loaded.

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?