{"id":5927,"date":"2023-03-13T16:15:01","date_gmt":"2023-03-13T20:15:01","guid":{"rendered":"https:\/\/optinmonster.com\/?post_type=optinmonster_docs&#038;p=5927"},"modified":"2025-08-22T07:36:39","modified_gmt":"2025-08-22T11:36:39","slug":"how-to-connect-optinmonster-with-any-custom-html-form","status":"publish","type":"optinmonster_docs","link":"https:\/\/optinmonster.com\/docs\/how-to-connect-optinmonster-with-any-custom-html-form\/","title":{"rendered":"How to Embed an HTML Form Into An OptinMonster Campaign"},"content":{"rendered":"\n<p>Creating forms is easy using our drag-and-drop editor, and connecting forms to the most popular <a href=\"https:\/\/optinmonster.com\/categories\/docs\/integrations\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Email Service Providers (ESP)<\/a> is too. But sometimes, you may need to use a custom form you&#8217;ve created yourself outside of OptinMonster, or to integrate with an email marketing platform we don&#8217;t yet support. Our <strong>Embed Form block<\/strong> is perfect for embedding an HTML or Javascript form into your OptinMonster campaign.<\/p>\n\n\n\n<p>In this article, you\u2019ll learn how to embed any HTML form into an OptinMonster campaign using the Embed Form block.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Before You Start<\/h2>\n\n\n\n<div class=\"alert-box alert-blue\">\n<p class=\"alert-box-title\"><\/p>\n\n\n\n<p>Are you looking to add extra fields to your optin form and prefer to use one of our native Integrations? <br><br><strong>Field Mapping<\/strong> is a brand-new feature available for our most popular Email Service Providers. You can easily add radio buttons, phone fields, text areas, number fields, lists, and more!<\/p>\n\n\n\n<p class=\"is-style-arrow-link has-link-color\"><a href=\"https:\/\/optinmonster.com\/docs\/use-field-mapping-to-add-extra-fields-to-your-optin-form\" target=\"_blank\" rel=\"noopener\" title=\"\">Learn more about Field Mapping<\/a><\/p>\n<\/div>\n\n\n\n<p><strong>Custom HubSpot forms<\/strong> must be edited <a href=\"https:\/\/optinmonster.com\/docs\/how-to-connect-optinmonster-with-custom-hubspot-form\/\" target=\"_blank\" rel=\"noopener\" title=\"\">following this guide<\/a> to function correctly.<\/p>\n\n\n\n<p><strong>Custom Marketo forms<\/strong> must be edited <a href=\"https:\/\/optinmonster.com\/docs\/how-to-connect-optinmonster-with-a-custom-marketo-form\/\" target=\"_blank\" rel=\"noopener\" title=\"\">following this guide<\/a> to function correctly.<\/p>\n\n\n\n<p><strong>Your custom form&#8217;s styling&nbsp;<\/strong>may need to be controlled using <a href=\"https:\/\/optinmonster.com\/docs\/how-to-use-optinmonsters-custom-css-tool\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Custom CSS<\/a>.<\/p>\n\n\n\n<p><strong>Looking to add a WordPress shortcode<\/strong> to your OptinMonster campaign?&nbsp;<a href=\"https:\/\/optinmonster.com\/docs\/how-to-use-wordpress-shortcodes-with-optinmonster\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Learn how to add shortcodes<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Embed Form<\/h2>\n\n\n\n<p>To add an HTML form to your OptinMonster campaign, follow these steps:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Navigate to the&nbsp;<strong>Design<\/strong> view of the campaign builder.<br><img decoding=\"async\" width=\"800\" height=\"581\" class=\"alignnone size-full wp-image-177675\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/design-view-campaign-builder.jpg\" alt=\"Design view of the campaign builder.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/design-view-campaign-builder.jpg 800w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/design-view-campaign-builder-300x218.jpg 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/design-view-campaign-builder-768x558.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li>\n\n\n\n<li>If your OptinMonster campaign already contains a <strong>Fields block<\/strong>, you&#8217;ll need to <strong>delete it<\/strong>.<br><img decoding=\"async\" width=\"800\" height=\"620\" class=\"alignnone size-full wp-image-177679\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/delete-fields-block.jpg\" alt=\"Delete any existing Fields block from the campaign.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/delete-fields-block.jpg 800w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/delete-fields-block-300x233.jpg 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/delete-fields-block-768x595.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li>\n\n\n\n<li>You can now drag the&nbsp;<strong>Embed Form block<\/strong> into your campaign&#8217;s design where you want to show the HTML form.<br><img decoding=\"async\" width=\"800\" height=\"504\" class=\"alignnone size-full wp-image-177678\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/add-embed-form-block.jpg\" alt=\"Add an Embed Form block to your OptinMonster campaign.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/add-embed-form-block.jpg 800w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/add-embed-form-block-300x189.jpg 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/add-embed-form-block-768x484.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li>\n\n\n\n<li>In the left sidebar panel the Embed Form block settings will provide a field for you to paste your HTML form&#8217;s embed code into.<br><img decoding=\"async\" width=\"800\" height=\"583\" class=\"alignnone size-full wp-image-177677\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/embed-form-block-settings.jpg\" alt=\"Add your HTML form embed code to the settings panel.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/embed-form-block-settings.jpg 800w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/embed-form-block-settings-300x219.jpg 300w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/embed-form-block-settings-768x560.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/li>\n\n\n\n<li><strong>Optional<\/strong>: You can configure additional styling settings for the Embed Form block in the&nbsp;<strong>Advanced<\/strong> tab of the left sidebar panel.<br><img decoding=\"async\" width=\"427\" height=\"1002\" class=\"alignnone size-full wp-image-177676\" src=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/embed-form-advanced-settings.jpg\" alt=\"Advanced settings for the Embed Form block.\" srcset=\"https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/embed-form-advanced-settings.jpg 427w, https:\/\/optinmonster.com\/wp-content\/uploads\/2023\/03\/embed-form-advanced-settings-128x300.jpg 128w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/li>\n\n\n\n<li><strong>Recommended<\/strong>: Update your HTML form embed code following <strong>the next section in this guide<\/strong> to track conversions and set cookies (to control how often the campaign can reappear).<\/li>\n\n\n\n<li>When you&#8217;re finished,&nbsp;<strong>Save<\/strong> the campaign.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"add-class\">Form Events<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Conversions and Cookies<\/h3>\n\n\n\n<p>There are two options to track conversions and <a href=\"https:\/\/optinmonster.com\/docs\/how-optin-cookies-and-the-global-cookie-work-in-optinmonster\/\" target=\"_blank\" rel=\"noopener\" title=\"\">set cookies<\/a> when your custom HTML form is submitted:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using Javascript (recommended, most accurate method)<\/li>\n\n\n\n<li>OR adding a class to the form&#8217;s submit button<\/li>\n<\/ul>\n\n\n\n<p>Whenever possible, you should use the Javascript method below on your form\u2019s success callback so that the conversion is only accurately recorded when your form is successfully submitted.<\/p>\n\n\n\n<p>If your custom HTML form is using Javascript on the <strong>submit<\/strong>&nbsp;event, then you\u2019ll want to ensure that the last line of the Javascript submit code is:<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/m5l9ry85.js\/\"><\/script>\n\n\n\n<p><strong>Notice:<\/strong>&nbsp;If you are doing any redirect if the submission is successful on your customized submission Javascript code, then there is nothing OptinMonster can do to track the conversion.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Javascript<\/h4>\n\n\n\n<p>Use the following Javascript on your form\u2019s success callback so that the conversion is only accurately recorded when your form is successfully submitted:<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/do1g91ro.js\/\"><\/script>\n\n\n\n<h4 class=\"wp-block-heading\">Button Class<\/h4>\n\n\n\n<div class=\"alert-box alert-yellow\">\n<p class=\"alert-box-title\">Note: <\/p>\n\n\n\n<p>Be aware that this method can result in false conversions being counted. Using the button class will count any click event on an element containing the class as a conversion. <br><br>If you add this to a submit button, for example, and the form fails to process successfully on the first click, it will still be counted as a conversion! Whenever possible, you should use the Javascript method provided above for the most accurate tracking.<\/p>\n\n\n\n<p class=\"is-style-arrow-link has-link-color\"><\/p>\n<\/div>\n\n\n\n<p>There is a particular class that you can use to notify OptinMonster that a conversion has happened and set cookies if they&#8217;ve been configured for your campaign.<\/p>\n\n\n\n<p>Add the class <code>om-trigger-conversion<\/code> to your custom form&#8217;s submit button. For example:<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/qor6pjxo.js\/\"><\/script>\n\n\n\n<h3 class=\"wp-block-heading\">Interactions<\/h3>\n\n\n\n<p>Separate from conversions, you can also count form interactions and pass that data to Google Analytics.<\/p>\n\n\n\n<p class=\"is-style-arrow-link\"><a href=\"https:\/\/optinmonster.com\/docs\/multiple-event-tracking-in-optinmonster-campaigns-using-google-analytics\/#Manual_Assignment\" target=\"_blank\" rel=\"noopener\" title=\"Learn how to track Custom HTML form interations\">Learn how to track Custom HTML form interactions<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Success Actions<\/h3>\n\n\n\n<p>You can customize the success action for your embedded form to change the campaign view or close the campaign.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Change View<\/h4>\n\n\n\n<p>Use one of the following Javascript examples on your form&#8217;s success callback to change to the specific campaign view you&#8217;d like to display on submission:<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/r2mg1ve2.js\/\"><\/script>\n\n\n\n<h4 class=\"wp-block-heading\">Close Campaign<\/h4>\n\n\n\n<p>Use the following Javascript on your form&#8217;s success callback to close the campaign on submission:<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/05krlx02.js\/\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\">Form Validation<\/h2>\n\n\n\n<p>You may wish to validate the fields in your embedded form but aren&#8217;t sure where to begin.<\/p>\n\n\n\n<p>The following are examples of validating an HTML form to help you get started.<\/p>\n\n\n\n<div class=\"alert-box alert-yellow\">\n<p class=\"alert-box-title\"><\/p>\n\n\n\n<p>These examples should not be used as-is but edited to fit your particular needs.<\/p>\n\n\n\n<p class=\"is-style-arrow-link has-link-color\"><\/p>\n<\/div>\n\n\n\n<p><strong>Javascript Validation Example<\/strong>:<\/p>\n\n\n\n<p>The following code provides an example of Javascript validation for an HTML form:<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/m5ygr745.js\/\"><\/script>\n\n\n\n<p><strong>Javascript Validation with AJAX Example<\/strong>:<\/p>\n\n\n\n<p>The following code provides an example of Javascript validation with AJAX for an HTML form:<\/p>\n\n\n\n<script src=\"https:\/\/library.wpcode.com\/embedjs\/32jj6n32.js\/\"><\/script>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"faq\">FAQs<\/h2>\n\n\n\n<h5 class=\"wp-block-heading\">How can I control the styling of my custom form?<\/h5>\n\n\n\n<p>Custom HTML forms do not automatically inherit the default styling of your optin template. You can control the appearance using Custom CSS.<\/p>\n\n\n\n<p class=\"is-style-arrow-link\"><a href=\"https:\/\/optinmonster.com\/docs\/how-to-use-optinmonsters-custom-css-tool\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Get started using Custom CSS with your campaign<\/a><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">My custom form is in an iFrame element. Can I still track conversions?<\/h5>\n\n\n\n<p>Due to the nature of iFrame elements, it is not possible to track clicks that take place within the iFrame element.<\/p>\n\n\n\n<p>This is a limitation of technology and not unique to OptinMonster.<\/p>\n\n\n\n<p>Whenever possible, you should use an HTML or Javascript form embed option if one is provided to you, instead of an iFrame embed.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">I&#8217;ve added the Embed Form block to my campaign, but the Integrations view in the builder is now disabled; why?<\/h5>\n\n\n\n<p>It is not possible to add a custom HTML form and connect with our native Integrations in a single campaign. If the Embed Form block is added to your campaign the Integrations view will be disabled. To resume using a native Integration you&#8217;ll need to first delete the Embed Form block from your campaign.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\" id=\"comments\">Why are my inline comments being wrapped by multi-line comments?<\/h5>\n\n\n\n<p>OptinMonster will wrap all inline comments into multi-line comments, which is necessary for OptinMonster&#8217;s proper handling and processing of the code involved.<\/p>\n\n\n\n<p>For example, this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Your Comments<\/code><\/pre>\n\n\n\n<p>becomes this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/* \/\/ Your Comments *\/<\/code><\/pre>\n\n\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h5 class=\"wp-block-heading\">I&#8217;m using the Button Class to track conversions but the number of conversions does not match the number of leads captured. Why?<\/h5>\n\n\n\n<p>Using the Button Class method can result in false conversions being counted.<\/p>\n\n\n\n<p>The Button Class will count any click event on an element containing the class as a conversion. If you add this to a submit button, for example, and the form fails to process successfully on the first click it will still be counted as a conversion!<\/p>\n\n\n\n<p>Whenever possible you should use the Javascript method provided above for the most accurate tracking.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">My Javascript form isn&#8217;t working; why?<\/h5>\n\n\n\n<p>Javascript-based forms are supported. However, a Javascript error in your form code may break your OptinMonster campaign. If that happens, please be sure to <a href=\"https:\/\/optinmonster.com\/docs\/getting-support-for-optinmonster\/\" target=\"_blank\" rel=\"noopener\" title=\"\">reach out to support<\/a> for assistance.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">My form isn&#8217;t submitting.<\/h5>\n\n\n\n<p>Check that the <code>&lt;form&gt;<\/code> tag in your embedded form code doesn&#8217;t contain the attribute <code>target=\"_blank\"<\/code>.<\/p>\n\n\n\n<p>Browsers have inconsistent support for this action (redirecting the visitor after form submission in a new tab\/window), and many will block it outright. This makes it appear your form is somehow broken. If your form contains this attribute, you can safely remove it and check again that the form submits appropriately.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating forms is easy using our drag-and-drop editor, and connecting forms to the most popular Email Service Providers (ESP) is too. But sometimes, you may need to use a custom form you&#8217;ve created yourself outside of OptinMonster, or to integrate with an email marketing platform we don&#8217;t yet support. Our Embed Form block is perfect&nbsp;&hellip;<\/p>\n","protected":false},"author":4657,"comment_status":"open","ping_status":"closed","template":"","documentation\/categories":[10],"documentation\/tags":[31399,31451,31487,31409,31411,31454],"class_list":["post-5927","optinmonster_docs","type-optinmonster_docs","status-publish","hentry","categories-integrations"],"acf":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/5927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation"}],"about":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/types\/optinmonster_docs"}],"author":[{"embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/users\/4657"}],"replies":[{"embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/comments?post=5927"}],"version-history":[{"count":45,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/5927\/revisions"}],"predecessor-version":[{"id":204575,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/5927\/revisions\/204575"}],"wp:attachment":[{"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/media?parent=5927"}],"wp:term":[{"taxonomy":"categories","embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/categories?post=5927"},{"taxonomy":"internal_tags","embeddable":true,"href":"https:\/\/optinmonster.com\/wp-json\/wp\/v2\/documentation\/tags?post=5927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}