Link to home
Create AccountLog in
Avatar of infodigger
infodigger

asked on

Retrieve form data and post them to URL

Hello,

Let's say we have a simple form on a site:

<form>
 <input type="text" name="foo" value="text1" />
<input type="submit" name="submit" value="submit />
</form>

I am looking to get the data once posted either with GET or POST through Javascript and post them to a different URL.

For example, let's say a user types "my text" and hits submit. Then I need to capture the "my text" and post it to a URL http://www.mydomain.com/getmyformdata.php?text=my text.

Is that possible all through Javascript?

Thanks a lot!
SOLUTION
Avatar of Manuel Marienne-Duchêne
Manuel Marienne-Duchêne
Flag of France image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Julian Hansen
why not just make the action of the form the url you want to post to?
just change your form tag to:

<form method="post" action="getmyformdata.php">

or

<form method="get" action="getmyformdata.php">

and on your php page, you would just retrieve the values based upon what method you used
If you use an url then it is going across using "get" if you want to use "post" you either have to use the form action or use ajax.

Cd&
Avatar of infodigger
infodigger

ASKER

The problem is that I don't have access to change these forms. I need the website owners to insert a javascript snippet in their code so that all form data are sent to my server as well when each form is submitted. Is that possible at all?
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Hi julianH,

Do you have any link/tutorial for this? I found this one http://neocotic.com/jquery-jsonx/ here but don't know how it helps.

Thanks a lot!
John
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.