I am trying to create a Smart Capture form in a Cloud Page. I would like to populate a hidden field with the current date. Can you use Ampscript to do this?
[SalesForce] Smart Capture Gear in Cloud Page
Related Solutions
This is briefly explained in the Smart Capture documentation. In short, you will need to:
- Pass the location name as a URL parameter to the landing page, for example, http://pages.example.com?location=sydney
- Create a hidden form field in your Smart Capture form named 'location'
- Use the AMPscript
RequestParameter()
function to retrieve the value of the URL parameter.
Here is some sample code:
%%[
var @location
set @location = RequestParameter("location")
]%%
<!-- include in your form -->
<input name="location" type="hidden" value="%%=v(@location)=%%" />
You will then create/update the 'location' Data Extension field with this hidden form field value.
There are 2 ways that we use to pass user information to Landing Pages:
Option 1: QueryParameter
In Email:
%%[VAR @email,@name,@landingpage
Set @email = 'email@example.com'
Set @name = 'Test'
Set @landingpage = Concat('https://pub.exacttarget.com/landingpage?email=',@email,'&name=',@name)
]%%
<a href = "%%=RedirectTo(@landingpage)=%%">Click Here</a>
On LandingPage:
<form>
Name:<br>
<input type="text" name="name" value="%%=v(QueryParameter('name'))=%%"><br>
Email:<br>
<input type="text" name="email" value="%%=v(QueryParameter('email'))=%%">
</form>
Option 2: LookupRows & DataView
In Email:
%%[VAR @subscriberkey,@landingpage
Set @subscriberkey= '123456789'
Set @landingpage = Concat('https://pub.exacttarget.com/landingpage?key=',@subscriberkey)
]%%
<a href = "%%=RedirectTo(@landingpage)=%%">Click Here</a>
On LandingPage:
%%[
var @key, @email, @name
set @key = QueryParameter("key")
set @email = FIELD(ROW(LookupRows("_Subscribers","SubscriberKey",@key),1), "EmailAddress")
set @name = FIELD(ROW(LookupRows("Example_Customer_Data_DE","SubscriberKey",@key),1), "Name")
]%%
<form>
Name:<br>
<input type="text" name="name" value="%%=v(@name)=%%"><br>
Email:<br>
<input type="text" name="email" value="%%=v(@email)=%%">
</form>
Note that both of these methods are taking values from AMPScript at the time of send, and appending them to the destination URL string. For this reason, you may need some security/hashing/encoding to prevent malicious attempts to access your customer data via the form.
I hope that helps.
Best Answer
You should be able to use the NOW( ) AMPScript function to achieve this. However, there is currently a known issue that doesn't allow you to simply use the %%=NOW()=%% in a hidden field's value. A workaround for this is to write your code without using an equal symbol.
For example, you would want to use something along the lines of the below. In your CloudPage, define the variable as such:
Then in your hidden smart capture field, declare this variable like this:
Further info on the NOW( ) Function can be found here: http://help.exacttarget.com/en/documentation/exacttarget/content/ampscript/ampscript_syntax_guide/datetime_ampscript_functions/#Now