Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a link that automatically fills a field on the target page

I'm coding a newsletter and the guy that asked me to do it wants a link in it...all perfect no problems...

Now the problem is that when you click on this link it goes on a page with fields and the guy asked me if it's possible to automatically fill up one of the fields.

The page is a subscription page for some services and this guy wants me to fill up the referral field automatically when you land on the page with his email. Is it possible?

Thanks heaps

like image 526
manujj88 Avatar asked Nov 24 '11 04:11

manujj88


1 Answers

One way to do this is to place the field name and value in the query string. The "query string" is the part of a URL which contains field/value pairs. It is separated from the page address by a ? followed by field=value pairs separated by & characters. For example,

http://www.example.com

...would become...

http://www.example.com?fieldName=fieldValue

In order for this to work, the page must parse the field as part of the HTTP GET request and then return the value as a pre-filled field. If the form is properly validated at the server side then it usually already has this capability of parsing fields and retaining their values across multiple submissions of the same form. This is because doing so allows the page to be redrawn with an error message if some fields are blank or have invalid values.

This is very easy to test - just find the field name in the page source and extend the URL you are currently using as shown above. If it works you are done. If not, you may need to get the code on the server side updated to accept the field as part of the query string.

Other ways to accomplish the same thing are more dependent on the server-side code. For example, many sites embed the associate referral ID in the URL such as:

http://www.example.com/123456/

In this case, server-side code interprets the directory path as a field and parses it accordingly. Because this requires very specific server-side code to support it, the first option is probably your best bet.

like image 197
T.Rob Avatar answered Oct 03 '22 08:10

T.Rob