Way to hide form on a landing page after a specified date? | Community
Skip to main content
Nicole_Burns2
New Participant
March 5, 2019
Solved

Way to hide form on a landing page after a specified date?

  • March 5, 2019
  • 1 reply
  • 5372 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jay_Jiang

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.

1 reply

Jay_Jiang
Jay_JiangAccepted solution
New Participant
March 5, 2019

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.

Nicole_Burns2
New Participant
March 5, 2019

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!

Jay_Jiang
New Participant
March 6, 2019

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.