Tip: Passing query string parameters to contact form page
Question:
Can I pre-fill in form fields from a URL query string?
Answer:
Yes, this feature was added in Version 2.9.7.1
What is a Query String? See query string at wikipedia
Here is an example, this is my contact form with a query string to pre-fill the name “My Test Name”:
http://www.fastsecurecontactform.com/contact?1name=My+Test+Name
Query String Rules:
- Begin all queries after the URL with a question mark, do not repeat question marks without URL encoding them.
- The query string is composed of a series of field-value pairs.
- The field-value pairs are each separated by an equals sign.
- The series of pairs is separated by the ampersand character &
- Do not use the ampersand, question mark, or equals character in strings without URL encoding them
- Spaces should be URL encoded as pluses.
- Each field name must begin with the form number (the four standard available forms are numbered 1,2,3,4)
- Field values must be url encoded to avoid problems.
- For security reasons, the Attachment fields and CAPTCHA field cannot be filled in by URL query.
- For security reasons, URL queries can only pre-fill the form, they cannot submit the form. This way security features like the CAPTCHA cannot be bypassed.
- You do not have to fill all the fields with URL queries, you can just fill one or two if you want. The user can fill in the rest.
- If using with extra fields, the extra fields must already be setup on the form edit page. For security reasons, you cannot dynamically add extra fields by query.
URL Encoding:
What us URL Encoding (percent encoding)? See article at wikipedia
Here is a site with a form to manually encode strings.
http://meyerweb.com/eric/tools/dencoder/
URL Encoding inside a PHP script:
<?php
$query_string = 'foo=' . urlencode($foo) . '&bar=' . urlencode($bar);
echo '<a href="mycgi?' . htmlentities($query_string) . '">click</a>';
?>
Available form fields to pass a URL query string to?
Standard Fields:
[form number]name=[string] (Name)
[form number]f_name=[string] (First Name)
[form number]mi_name=[string] (Middle Initial)
[form number]l_name=[string] (Last Name)
[form number]email=[string] (E-Mail Address)
[form number]mailto_id=[number] (use when the Email To: is a drop down list)
[form number]subject=[string] (Subject)
[form number]subject_id=[number] (use when the Subject: is a drop down list)
[form number]message=[string] (Message)
Example: Using a query for the Name field on form number 1:
?1name=Mike+Challis
Example: Using a query for the Name field and Email field on form number 2:
?2name=Mike+Challis&2email=name%40company.com
Extra fields with query input:
Types: text, textarea, date, password, hidden
[form number]ex_field[field number]=[string]
Example: form 4 using extra field 2 for text (phone number):
&4ex_field2=555-555-2125
Types: checkbox(single)
[form number]ex_field[field number]=1 (checked)
Example: form 1 using extra field 4 for checkbox(single)
(Join newsletter):
?&1ex_field4=1
Types: checkbox(multiple), select-multiple
[form number]ex_field[field number]_[option number]=1 (checked)
Example: form 1 using extra field 5 for checkbox(multiple)
(Pizza Toppings: olives mushrooms cheese ham tomatoes)
?&1ex_field5_2=1&1ex_field5_3=1
(mushrooms option 2, and cheese option 3, selected)
Types: radio, select
[form number]ex_field[field number]=[option number] (checked)
Example: form 3 using extra field 7 for radio (select option 2, no)
(Do you like Onions? yes, no)
?&3ex_field7=2 (no) will be selected
Types: time
[form number]ex_field[field number]h=[number] (hour 01-12)
[form number]ex_field[field number]m=[number] (minute 00-59)
[form number]ex_field[field number]ap=[string] (AM or PM)
Example: form 1 using extra field 11 for time: 04:30PM
?&1ex_field11h=04&1ex_field11m=30&1ex_field11ap=PM
Discuss in the WordPress Support Forum
Do you need help?Donations by PayPal:
Donations by cash or check:
Mike Challis
PO Box 819
Long Beach WA 98631


