Pass the current URL as a hidden field through HTML form.
I have an HTML contact form on many different pages of a web site. I need to know which page the user was on when they submit the form.
I need to pass the URL of the current page as a hidden field through the form when it's submitted. Please be specific with the code, as I'm nowhere near an expert at this.
Do I need to add javascript to the header to call a function pulling the URL and then a secondary function to place it in the hidden field's "value" attribute?
So, do I need to somehow enclose that javascript to keep it from showing up on the web page? I put that code right below the <input> hidden field, but it shows up right on the web output page.
Does it need to be saved as php or something? Like I said, I'm new at this.
you haven't posted your updated code so how the heck do you expect someone to tell you what you have done wrong?
Did you put your javascript inside a <script> tag? Why not post your code so we can see what is going on?
I'm assuming you want to learn how to do this and not just want someone to spoon feed you the code. I've already given you 99.9% of it.
If you want to learn how to add javascript to your page a quick google will give you a ship load of information - one example set of tutes
If you want someone to just spoon feed you the code, then hopefully someone else will come along.
In any case, you'd be better off getting the page's url from a server side script rather than using javascript because obviously the javascript solution won't work in javascript disabled browsers.
Last edited by webdev1958; 12-16-2011 at 07:41 PM.
which will put the name of the script that was used to post, so your input field will be whatever name the page is that posted the comment or form. you would need to use a different method of identifying if your pages are all called index, you would need to include the relative path on the domain, similar process to that just demonstrated.
We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
Code:
Youre = {
STILL_not_getting_it:function(){
alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
},
MissingThePoint:function(msg){
alert("You're missing the point. " + msg);
}
}
Youre.STILL_not_getting_it();
I appreciate the constructive criticism, should've posted more code. Thanks for the code so far, Javascript worked, as did the server-side, but as you said I just get the script filename. I added REQUEST_URI and got the full relative path now, but still no domain/full URL.
I'd like the value to show up as a full hyperlink, so I manually added the http://domainname but that's not the best way to do it, I'm sure. Here's what's working now:
I don't know but you may need to lose the ."/". for a . to join the string. $_SERVER['REQUEST_URI'] may be prefixed with a / which means you wouldn't need the ."/".
We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
Code:
Youre = {
STILL_not_getting_it:function(){
alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
},
MissingThePoint:function(msg){
alert("You're missing the point. " + msg);
}
}
Youre.STILL_not_getting_it();
Bookmarks