I have an html form and I need to populate one of the input fields with the url of the page the form is on. To get the url I have:
<?php $pageURL="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];?>
To populate the input field I have:
<script type="text/javascript">
// <![CDATA[
$(document).ready(function(){
var getLabel = $(".monkForm label:contains('Page URL')");
var getFor = getLabel.attr('for');
var splitFor = getFor.split('_');
var inputID = $("#" + getFor );
var wrapID = $("#w" + splitFor[1] );
wrapID.hide();
inputID.val('<?=$pageURL;?>');
});
// ]]>
</script>
The input field label on the form is “Page URL”. The problem is that the page URL is not being added to the input field.
You can’t use PHP as it is server side. Get the URL using Javascript instead: