PDA

View Full Version : Passing form data in URL using post method



Chuka
12-18-2006, 01:44 PM
Hi all,

I am trying to pass data from a form field (to help adsense target ads) and I am running into a wall. I know it should not be that hard and there should be a script that can help.

Anyway, here's the scoop. Normal form, using the POST method. I just want to take a form field (which will be the name of a state) and add it into the URL when the user clicks on submit.

Anyone have any pointers or examples? Thank you in advance.

djr33
12-18-2006, 10:00 PM
Hmm.... Random guess, untested....

<form action="page.php" method="post" onSubmit="this.action=this.action+'?var='+urlbit.value>
<input type="text" id="urlbit">
</form>


the problem is that it relies on javascript, so it won't work if the user doesn't have that enabled. So... make sure there's some sort of fallback. If possible, have a server side backup.

If possible, you may wish to just set the action of the form with a default get variable, like action="page.php?var=1". That might just solve your whole problem, but if not, at least you have a default value if JS is disabled.