|
|
Documentation Wiki > ExactTarget > Content > Landing Pages > Using AMPscript to Validate Fields in a Landing Page
Using AMPscript to Validate Fields in a Landing PageFrom $1This document contains conceptual and procedural information about using AMPscript to validate fields in a landing page. PrerequisitesYou must have landing pages enabled for your account. Contact your ExactTarget representative if you have any questions about using landing pages with your ExactTarget account. Why Use ValidationValidation ensures that your subscribers enter correctly formatted information in your landing page. You can set rules governing the data entered in your landing page fields that prevent entries with too few or too many characters (such as a ZIP code or phone number) or force subscribers to enter data in a required field. How to Use Validation AMPscript in Your Landing Page on LOADFirst, you must create variables in your landing page. In this example, the code includes two variables and sets @zip to the value entered in a landing page field called "ZIP." <html>
%%[ Var @zip, @redirURL
Set @zip = RequestParameter("zip")
The next part of the code evaluates the number of characters included in the value of @zip. If there are five characters, it passes the variable to the page. /* We have 5 characters */
if Length(@zip) == 5 then
Set @redirURL = Concat("http://exacttarget.com?zip=",@zip) ]%%
<head>
<META http-equiv="refresh" content="0;URL=%%= v(@redirURL) =%%" />
</head>
<body>
</body>
If there are less than five characters in the page, it prompts the subscriber for a correct entry: %%[ elseif Length(@zip) < 5 then ]%%
<head>
</head>
<body>
<h1>Show the form again and prompt for the correct number of characters</h1>
</body>
Finally, if the subscriber fails to enter a ZIP code, the landing page prompts them for an entry: %%[ elseif Empty(@zip) == "true" then ]%%
<head>
</head>
<body>
<h1>Show the form again and state the zip code field is required</h1>
</body>
%%[ endif ]%%
</html>
How to Use Validation AMPscript in Your Landing Page on POSTIf you want your AMPscript to validate the information on POST and not LOAD, you can include the following elements in your form. First, build the form and HTML according to your needs. In the body of the page, include the following form tag: <form method="POST" action="%%= RequestParameter('PAGEURL') =%%">
This ensures that when the form posts, it goes back to the form. The form should also include two hidden fields: <input id="__contextName" type="hidden" name="__contextName" value="fieldName" /> <input id="__executionContext" type="hidden" name="__executionContext" value="Post" /> You can also include the following two optional hidden fields. These fields point the subscriber to different pages depending on whether the form was completed successfully or incorrectly. <input type="hidden" __errorPage="http://example.com/error"> <input type="hidden" __successPage="http://example.com/success"> Finally, include the following AMPscript in your page: %%[
[name="fieldName";type="POST"]
VAR @zip, @Test
SET @zip = RequestParameter("zip")
IF Empty(@zip) == "true" THEN
RaiseError("Please enter a valid ZIP code.")
]%%
<form method="POST" action="%%= RequestParameter('PAGEURL') =%%">
This page was last updated by Ryan Williams on Tue, 20 Dec 2011 13:59:27 GMT. If you require assistance with the ExactTarget application, please contact Global Support. If you wish to send Ryan direct feedback, fill out the form below:
Tags: (Edit tags)
|
Powered by MindTouch 2010 |