将HTML参数传递给php页面

我试图使用表单将当前html页面的参数传递给php页面。 到目前为止,我在html中的标题内有以下函数</ p>

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

&lt; / script&gt;
</ code> </ pre>

然后在表单中我有以下内容</ p>

 &lt; input type =“hidden”name =“amtpaid”id =“amtpaid”value =“getURLParameter('amt')”/&gt; 
&lt; input type =“hidden”name =“status” id =“sts”value =“getURLParameter('st')”/&gt;
</ code> </ pre>

这假设网址如</ p>


www.somehost.com/page/?amt=5&amp;sts=CONFIRMED </ p>
</ blockquote>

但是,所说的所有内容都是 以下(这是所有发布数据的转储)</ p>

 数组([on1] =&gt; Steam 32  -  ID(STEAM_0:X:XXXX)[os1] =&gt  ; hj [amtpaid] =&gt; getURLParameter('amt'); [status] =&gt; getURLParameter('st');)
</ code> </ pre>

anyhelp ?? < / p>
</ div>

展开原文

原文

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个回答



您将文字字符串“getUrlParameter('amt')”作为您要发布的字段的值传递。 您无法以这种方式填充“值”。 您需要做的是从javascript填充值。 像这样:</ p>

  document.getElementById(“amtpaid”)。value = getUrlParameter('amt'); 
document.getElementById(“sts”)。value = getUrlParameter(' st');
</ code> </ pre>

这需要放在页面的脚本标签中的某个位置,在适合您应用程序的时间执行它 在加载了这两个隐藏字段之后。 </ p>
</ div>

展开原文

原文

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.

douzi5214
douzi5214 谢谢你,我没想到这一点
3 年多之前 回复



将此脚本放在表单或输入字段下:</ p>

 

var amount = getURLParameter('amt');
var stat = getURLParameter('sts');
document.getElementById(“amtpaid”)。value = amount;
document.getElementById(“sts”)。value = stat; \ n
</ pre>
</ div>

展开原文

原文

Put this script under your form or input fields:


    var amount = getURLParameter('amt');
    var stat = getURLParameter('sts');
    document.getElementById("amtpaid").value = amount;
    document.getElementById("sts").value = stat;

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问