Hi there!
Curious if there is a way to hide a form that appears on a landing after a certain date? Use case being, the event is over and I want to avoid any future submissions. I do not want to have to go in manually to update the landing page but rather use some kind of scripting to hide/remove the form after the last date of the event.
I realize there is an option to display custom text instead of the form if the visitor is known but I am trying to deter new submissions. I also see there are form settings at the landing page level but it is only for the followup page after submission.
I have seen this article about what to do with post-event landing pages, but I don't necessarily want to push visitors to any on-demand content or current content. I have also seen articles (like this one that Sanford answered) about conditionally showing the submit button, which might work, but I can't quite figure out what condition I would use and how it could be influenced by the date.
I am somewhat new to Marketo so I may be overlooking something really obvious! Sorry if I am!
Any suggestions would be wonderful! Thanks! =D
Solved! Go to Solution.
If you have the event date in a program token already...
You can add a script like this:
<script>
MktoForms2.whenReady(function(form) {
var eventDate = new Date("{{my.eventdate}}"),
today = new Date(),
formEl = form.getFormElem()[0];
eventDate.setHours(0,0,0,0);
today.setHours(0,0,0,0);
if(eventDate<today){formEl.innerHTML = "This event is over"}
});
</script>
N.B. this ignores timezones and assumes the person visiting the landing page and the event are all in the same timezone.
If you have the event date in a program token already...
You can add a script like this:
<script>
MktoForms2.whenReady(function(form) {
var eventDate = new Date("{{my.eventdate}}"),
today = new Date(),
formEl = form.getFormElem()[0];
eventDate.setHours(0,0,0,0);
today.setHours(0,0,0,0);
if(eventDate<today){formEl.innerHTML = "This event is over"}
});
</script>
N.B. this ignores timezones and assumes the person visiting the landing page and the event are all in the same timezone.
Thank you so much Jay! This is perfect!
I have tried adding this script to the landing page a few ways and it isn't working but could be a setting on the landing page itself or something I am doing wrong. I'll keep trying.
Thanks again!
One thing I left out is that the script needs to be added after the form. Having the script before the form will not work.
Thanks for this! Unfortunately, I do not have that element available to me but I will use this article from Gregoire to figure out a way to add it, obviously keeping in mind the placement below the form.
Thanks again for all the help!
UPDATE: WOO HOO!! I was able to simply add as an HTML in a basic text element and it worked like a charm! Thank you again, Jay!
@jay - this is great! Can you add HTML elements in this replacement text (such as an anchor tag to direct to a replay page)?
innerHTML treats strings as HTML always, so yes.