SOLVED

Error Message on Event Expiration

Go to solution
Vidhi
Level 2

Error Message on Event Expiration

Hi,

I was trying this solution available in the community already to display an error message and hide the form on my Landing Page once the event is over:

<!DOCTYPE html>
<html>
<head>
<style>
.formHolder{
display: block;
}
</style>
</head>
<script language="JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>

<script>

MktoForms2.whenReady(function(form) {

var today = new Date(); //set the current date

var registrationClose = Date.parse("{{my.WBNExpirationDate}}"); //change to your desired date

if (today > registrationClose) {
$(".mktoForm").wrap( "<div class='formHolder'></div>" );

$(".mktoForm").hide();

$(".formHolder").append('<div><p>{{my.ErrorMessage}}</p></div>'); //change to your desired content here, set appropriate classes/IDs for styling
};

});

</script>
</html>

However, my error message is displayed twice. Perhaps, I am not setting the div class correctly.

Can someone check my code & give me some inputs.

 

Kind Regards!

 

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Error Message on Event Expiration

The problem is actually that you’re selecting too many elements here:

$(".mktoForm").wrap( "<div class='formHolder'></div>" );

 

You have a built-in handle to the current form’s jQuery wrapper, use that:

form.getFormElem().wrap( "<div class='formHolder'></div>" );

 

View solution in original post

6 REPLIES 6
SanfordWhiteman
Level 10 - Community Moderator

Re: Error Message on Event Expiration

Please remember to use the syntax highlighter when posting code, so it’s readable. I edited your post this time.

 

You’re firing code on whenReady() which means it runs once for every form on the page.

Vidhi
Level 2

Re: Error Message on Event Expiration

Hi @SanfordWhiteman ,

Apologies, I forgot to use the code editor earlier in rush.

Thanks for your reply. I was checking and in my Landing Page, I am just using one form though.

Sorry,  but how can I resolve this issue or check if there are multiple forms on the page.

 

Kind Regards,

Vidhi

 

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Error Message on Event Expiration

You have to link to your page.

 

Also misleading to imply you’re showing the whole <html> element in the post when clearly that can’t be true!

Vidhi
Level 2

Re: Error Message on Event Expiration

Hi,

I might be wrong as I had added HTML to the free-form landing page just below the form section and then added the script code there.

Here is the link to my LP - https://600-ARX-277.mktoweb.com/lpeditor/devicePreview?p=1278&t=08kAGZCsxThVebL7xP3oxQ,,&m=600-ARX-2...

Any help will be appreciated.

 

Kind Regards,

Vidhi

SanfordWhiteman
Level 10 - Community Moderator

Re: Error Message on Event Expiration

The problem is actually that you’re selecting too many elements here:

$(".mktoForm").wrap( "<div class='formHolder'></div>" );

 

You have a built-in handle to the current form’s jQuery wrapper, use that:

form.getFormElem().wrap( "<div class='formHolder'></div>" );

 

Vidhi
Level 2

Re: Error Message on Event Expiration

Hi @SanfordWhiteman ,

 

Thank you! It solved my issue! Appreciate your help always.

Have a nice day ahead!!

 

Kind Regards,

Vidhi