Hi Guys, a little help here:
O used to have a input type="text" in a form of mine with
value="<?php echo $_SERVER['HTTP_REFERER']; ?>
and it stopped working.
I went back to code and now is showing
value="<?php echo $_SERVER['HTTP_REFERER']; ?>
so I believe that it stopped working due to this caracthere conversion.
Anyone has another code that would record the URL as value via js using input id or name?
Or anyother way that you might think that would work better?
Tks
Solved! Go to Solution.
for that, you can update with the following code :
$("input[name=urlencodeenable]").val(document.URL);
or
$("input[name=urlencodeenable]").val(window.location.href );
kindly Accept as a Solution if this works for you and give Kudos
seems like you are using this in Admin CMS Area
then you need to use JS to fill referrer
for that, you can update the form with following
<input type="hidden" id="referrer" value="" >
and a JS
<script> require(['jquery'], function($){ $(document).ready(function() { $("input[id=referrer]").attr('value', document.referrer); }); }); </script>
this will fill the input with the referrer.
@amitsamsukha yes, it´s a cms block actually.
I´d tried your code however is not retrieving URL, it´s still blank. I´d cleaned magento cache and browser cache after changes as you suggested.
Here is my input:
<input id="referrer" hidden="" maxlength="255" name="cf_contacts_urlcontato" type="text" value="" data-label="" />
Here is script:
<script type="text/javascript" xml="space">// <![CDATA[ require(['jquery'], function($){ $(document).ready(function() { $("input[id=referrer]").attr('value', document.referrer); }); }); // ]]></script>
can you give me URL so that I can check and help
sure @amitsamsukha I will send URL via private message.
Just want to explain that the form is inputed via block on CMS pages, so I´d live to know in which page the form as sent from.
you have placed the wrong ID in the script
kindly try updating the script with the same id that is used for input
<script type="text/javascript" xml="space">// <![CDATA[ require(['jquery'], function($){ $(document).ready(function() { $("input[name=urlencodeenable]").val(document.referrer); }); }); // ]]></script>
@amitsamsukha I followed your instruction and now is showing www.google.com, I believe this is where the user was initially forwarded from, right? Actually it´s kind of usefull, I think I will keep that as well.
However my initial need that is to get URL where fom was filled out is still pending.
for that, you can update with the following code :
$("input[name=urlencodeenable]").val(document.URL);
or
$("input[name=urlencodeenable]").val(window.location.href );
kindly Accept as a Solution if this works for you and give Kudos
@amitsamsukha thank you very much! Working again now!
In pure jQuery style:
$(location).attr('href');
The location object also has other properties, like host, hash, protocol, and pathname.
var x = $(location).attr('<property>');
Also, you can get this done by using JavaScript's built-in window.location object .
var pathname = window.location.pathname; // Returns path only var url = window.location.href; // Returns full URL var origin = window.location.origin; // Returns base URL