One for the Gurus! Pulling URL in a form

cemt

Well-Known Member
Joined
Jun 1, 2004
Messages
372
Reaction score
1
Location
Sandton
Hi Gurus!

I want the Form Location to be pulled in Form results

I have a simple Post HTML Form on a PHP Server, which is the simplest way to pull the page url it was submitted from?

Any simple PHP code to achive this?

I'm using Formtools so I cant rewrite the forms processor.

Thanks in Advance!
:confused:
 
Booya.... cemt, this dude needs a beer!

thanks dudes! i will give a 6pack to get this right!

I've been using this but it doesnt seem to work for me

<input type="hidden" name="referer_url" value="<?php echo $_SERVER["HTTP_REFERER"]?>" />

all I get is /> in my form
 
For that use, do this:

<input type="hidden" name="referer_url" value="<?php echo ($_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]) ?>" />

Which will pass the URL of the page that contains the form to the page that processes the form. Note: this includes the domain; you may want to leave off the $_SERVER["SERVER_NAME"] part.
 
if you are deving on your machine, and go directly to the form in your browser, then of course referer will be empty

I dont even think this is what you want anyway.

you want to go to "contact_us.php", and your POST to then contain "contact_us.php"? you can use the javascript functions "encodeURIComponent(document.URL)" for that

something like

$(document).ready(function(){
$('#hidden-field-id).val(encodeURIComponent(document.URL));
});
(assuming you are using jquery)

edit: I see someone also posted above using php and $SERVER. I am not 100% sure how PHP works, but this will give problems with url rewriting. eg if the browser sees /contact-us/, but this is actually a rewritten /contact-us.php, then your form will record "contact-us.php". this may or may not be a problem for you.
 
Last edited:
op, is php parsable in formtools?
it would be unusual for a public form builder to allow this imo...
 
Thanks all you gurus! my php knowledge is very limited

Ok I think the problem is the site is in Joomla, using MOD-REWRITE, I'm using Formtools, I think its the mod rewrite.

Can this be done in Javascript?
 
Thanks all you gurus! my php knowledge is very limited

Ok I think the problem is the site is in Joomla, using MOD-REWRITE, I'm using Formtools, I think its the mod rewrite.

Can this be done in Javascript?

my post 4 up shows in JS :)
 
Top
Sign up to the MyBroadband newsletter
X