{"id":165,"date":"2017-01-18T01:01:14","date_gmt":"2017-01-18T01:01:14","guid":{"rendered":"http:\/\/jtc-art.com\/code-blog\/?p=165"},"modified":"2017-01-18T01:20:05","modified_gmt":"2017-01-18T01:20:05","slug":"how-to-send-2-html-forms-at-once","status":"publish","type":"post","link":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/","title":{"rendered":"How to send 2 HTML forms at once"},"content":{"rendered":"<p>I was doing a project and it required that I sent the same information to 2 different sites using 2 different forms. It wasn&#8217;t easy to edit the back end code so I couldn&#8217;t used the API. After researching I came up with this solution.<\/p>\n<ol>\n<li>Hide the second form with CSS\n<pre> &lt;form style=\"display:none;\"....<\/pre>\n<\/li>\n<li>When the first form is submitted do 3 things.\n<ol>\n<li>Populate the second form using the values from the first. I used jQuery .val\n<pre> var name = $(\"#name\").val();\r\n\r\n $(\"#name2\").val(name);<\/pre>\n<\/li>\n<li>Send the first form through an IFrame.\n<pre> &lt;form target=\"iFrameID\"....<\/pre>\n<\/li>\n<li>Set the thank you page for the form to come back to an html file with basic HTLM code and a script like this to trigger a function to send the second form. <strong>This page has to be on the original domain so it doesn&#8217;t violate the cross domain rules.<\/strong>\n<pre> &lt;script&gt;\r\n\r\n parent.sendForm2();\r\n\r\n &lt;\/script&gt;<\/pre>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p>Example of code for the main page&#8230;.<\/p>\n<pre>&lt;iframe id=\"iFrame1\" name=\"iFrame1\"&gt;&lt;\/iframe&gt;\r\n\r\n&lt;form id=\"form1\" target=\u201diFrame1\u2033&gt;\r\n   Name: &lt;input type=\u201dtext\u201d id=\u201dname\u201d name=\u201dname\u201d\/&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;form id=\u201dform2\u2033 style=\u201ddisplay:none;\u201d&gt;\r\n   Name: &lt;input type=\u201dtext\u201d id=\u201dname2\u2033 name=\u201dname\u201d\/&gt;\r\n&lt;\/form&gt;\r\n\r\n&lt;script&gt;\r\nfunction sendForm1(){\r\n   $(\u201c#form1\u201d).submit();\r\n}\r\n\r\nfunction sendForm2(){\r\n   $(\u201c#form2\u201d).submit();\r\n}\r\n\r\nfunction populateForm2(){\r\n   var name = $(\u201c#name\u201d).val();\r\n   $(\u201c#name2\u201d).val(name);\r\n   sendForm1();\r\n}\r\n\r\n$(\"#form1\").submit(function() {\r\n   populateForm2();\r\n   return false;\r\n});\r\n&lt;\/script&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>Example of code for the thank you page (for the first form) HTML file &#8230;.<\/p>\n<pre>&lt;!DOCTYPE html&gt;\r\n&lt;html lang=\"en-US\"&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=\"UTF-8\"&gt;\r\n&lt;script&gt;\r\nparent.sendForm2();\r\n&lt;\/script&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;p&gt;Sending...&lt;\/p&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>Note:<\/strong> This page has to be on the original domain so it doesn&#8217;t violate the cross domain rules. If you need to do it with a subdomain you could add <em>document.domain = &#8220;subdomain.mydomain.com&#8221;;<\/em> to the main page and the thank you page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was doing a project and it required that I sent the same information to 2 different sites using 2 different forms. It wasn&#8217;t easy to edit the back end code so I couldn&#8217;t used the API. After researching I came up with this solution. Hide the second form with CSS &lt;form style=&#8221;display:none;&#8221;&#8230;. When the &hellip; <a href=\"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">How to send 2 HTML forms at once<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[19,18],"class_list":["post-165","post","type-post","status-publish","format-standard","hentry","category-code-snippets","tag-html-forms","tag-send-2-forms"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to send 2 HTML forms at once - Code Blog<\/title>\n<meta name=\"description\" content=\"Get the example code to send 2 forms at once with out using an API. I also explain the logic behind it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to send 2 HTML forms at once - Code Blog\" \/>\n<meta property=\"og:description\" content=\"Get the example code to send 2 forms at once with out using an API. I also explain the logic behind it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/\" \/>\n<meta property=\"og:site_name\" content=\"Code Blog\" \/>\n<meta property=\"article:published_time\" content=\"2017-01-18T01:01:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-01-18T01:20:05+00:00\" \/>\n<meta name=\"author\" content=\"Jason Campbell\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jason Campbell\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/\"},\"author\":{\"name\":\"Jason Campbell\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#\\\/schema\\\/person\\\/2ecb375f4b2fdd46b424aa06c592a85b\"},\"headline\":\"How to send 2 HTML forms at once\",\"datePublished\":\"2017-01-18T01:01:14+00:00\",\"dateModified\":\"2017-01-18T01:20:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/\"},\"wordCount\":202,\"commentCount\":0,\"keywords\":[\"html forms\",\"send 2 forms\"],\"articleSection\":[\"Code Snippets\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/\",\"url\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/\",\"name\":\"How to send 2 HTML forms at once - Code Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#website\"},\"datePublished\":\"2017-01-18T01:01:14+00:00\",\"dateModified\":\"2017-01-18T01:20:05+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#\\\/schema\\\/person\\\/2ecb375f4b2fdd46b424aa06c592a85b\"},\"description\":\"Get the example code to send 2 forms at once with out using an API. I also explain the logic behind it.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/how-to-send-2-html-forms-at-once\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to send 2 HTML forms at once\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#website\",\"url\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/\",\"name\":\"Code Blog\",\"description\":\"The Code Blog of Jason T Campbell\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/#\\\/schema\\\/person\\\/2ecb375f4b2fdd46b424aa06c592a85b\",\"name\":\"Jason Campbell\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g\",\"caption\":\"Jason Campbell\"},\"url\":\"https:\\\/\\\/jtc-art.com\\\/code-blog\\\/author\\\/jasonc\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to send 2 HTML forms at once - Code Blog","description":"Get the example code to send 2 forms at once with out using an API. I also explain the logic behind it.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/","og_locale":"en_US","og_type":"article","og_title":"How to send 2 HTML forms at once - Code Blog","og_description":"Get the example code to send 2 forms at once with out using an API. I also explain the logic behind it.","og_url":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/","og_site_name":"Code Blog","article_published_time":"2017-01-18T01:01:14+00:00","article_modified_time":"2017-01-18T01:20:05+00:00","author":"Jason Campbell","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Jason Campbell","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/#article","isPartOf":{"@id":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/"},"author":{"name":"Jason Campbell","@id":"https:\/\/jtc-art.com\/code-blog\/#\/schema\/person\/2ecb375f4b2fdd46b424aa06c592a85b"},"headline":"How to send 2 HTML forms at once","datePublished":"2017-01-18T01:01:14+00:00","dateModified":"2017-01-18T01:20:05+00:00","mainEntityOfPage":{"@id":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/"},"wordCount":202,"commentCount":0,"keywords":["html forms","send 2 forms"],"articleSection":["Code Snippets"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/","url":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/","name":"How to send 2 HTML forms at once - Code Blog","isPartOf":{"@id":"https:\/\/jtc-art.com\/code-blog\/#website"},"datePublished":"2017-01-18T01:01:14+00:00","dateModified":"2017-01-18T01:20:05+00:00","author":{"@id":"https:\/\/jtc-art.com\/code-blog\/#\/schema\/person\/2ecb375f4b2fdd46b424aa06c592a85b"},"description":"Get the example code to send 2 forms at once with out using an API. I also explain the logic behind it.","breadcrumb":{"@id":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jtc-art.com\/code-blog\/how-to-send-2-html-forms-at-once\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jtc-art.com\/code-blog\/"},{"@type":"ListItem","position":2,"name":"How to send 2 HTML forms at once"}]},{"@type":"WebSite","@id":"https:\/\/jtc-art.com\/code-blog\/#website","url":"https:\/\/jtc-art.com\/code-blog\/","name":"Code Blog","description":"The Code Blog of Jason T Campbell","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jtc-art.com\/code-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/jtc-art.com\/code-blog\/#\/schema\/person\/2ecb375f4b2fdd46b424aa06c592a85b","name":"Jason Campbell","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a4a4c7111068f877b9afce9f62af6b28c85f862d9cbe6d194eaaf3c83939766f?s=96&d=mm&r=g","caption":"Jason Campbell"},"url":"https:\/\/jtc-art.com\/code-blog\/author\/jasonc\/"}]}},"_links":{"self":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts\/165","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/comments?post=165"}],"version-history":[{"count":6,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts\/165\/revisions"}],"predecessor-version":[{"id":171,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/posts\/165\/revisions\/171"}],"wp:attachment":[{"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/media?parent=165"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/categories?post=165"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jtc-art.com\/code-blog\/wp-json\/wp\/v2\/tags?post=165"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}