Reputation: 183
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??
Upvotes: 0
Views: 227
Reputation: 38
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;
Upvotes: 0
Reputation: 827
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.
Upvotes: 1