{"id":6864,"date":"2022-10-21T09:32:30","date_gmt":"2022-10-21T13:32:30","guid":{"rendered":"https:\/\/themespress.ca\/?p=6864"},"modified":"2022-10-30T12:03:25","modified_gmt":"2022-10-30T16:03:25","slug":"wordpress-table-formidable-form-data","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/wordpress-table-formidable-form-data\/","title":{"rendered":"WordPress Table: Formidable Form Data"},"content":{"rendered":"<div class=\"wpb-content-wrapper\"><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>You want to create a new data entry in a custom WordPress table from a Formidable form? Let&#8217;s say you want to create a table in order to get data from a form or generate stats. <\/p>\n<p>Once your table has been created with the required columns, <strong>you need to make sure that the columns matches your form&#8217;s fields.<\/strong><\/p>\n<p>If you want to create a table with a function, here&#8217;s an interesting article that explains a function that will <a href=\"https:\/\/deliciousbrains.com\/creating-custom-table-php-wordpress\/\" target=\"_blank\" rel=\"noopener\"><strong>create a WordPress table<\/strong><\/a><\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div  class=\"wpb_single_image wpb_content_element vc_align_left wpb_content_element\">\n\t\t\n\t\t<figure class=\"wpb_wrapper vc_figure\">\n\t\t\t<div class=\"vc_single_image-wrapper   vc_box_border_grey\"><img decoding=\"async\" width=\"1903\" height=\"955\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable.png\" class=\"vc_single_image-img attachment-full\" alt=\"Create a table from data obtained via a Formidable form\" title=\"Create a table from data obtained via a Formidable form\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable.png 1903w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable-600x301.png 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable-300x151.png 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable-1024x514.png 1024w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable-768x385.png 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable-1536x771.png 1536w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creer-une-entree-table-venant-dun-formulaire-Formidable-1320x662.png 1320w\" sizes=\"(max-width: 1903px) 100vw, 1903px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-7706825\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-7706825\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"standard\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\/\/ Create database table\n\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\nfunction database_wooclassementstats() {\n\tglobal $wpdb;\n\t$charset_collate = $wpdb-&gt;get_charset_collate();\n\t$table_name = $wpdb-&gt;prefix . &#039;wooclassementstats&#039;;\n\t\t$sql = &quot;CREATE TABLE $table_name (\n\t\tid mediumint(9) NOT NULL AUTO_INCREMENT,\n\t\tviewdate date DEFAULT &#039;0000-00-00&#039; NOT NULL,\n\t\tviewtime time DEFAULT &#039;00:00:00&#039; NOT NULL,\n\t\tproductid int(11) NOT NULL,\n\t\tproductname varchar(60) NOT NULL,\n\t\tproducturl text NOT NULL,\n\t\tuserip varchar(60) NOT NULL,\n\t\tusername varchar(60) NOT NULL,\n\t\tuserid bigint(20) NOT NULL,\n\t\tusercountry text NOT NULL,\n\t\tusercity varchar(255) NOT NULL,\n\t\tuserbrowser varchar(255) NOT NULL,\n\t\tuserbrowserversion varchar(255) NOT NULL,\n\t\tuserbrowserplateform varchar(255) NOT NULL,\t\n\t\tuserviews smallint(5) NOT NULL,\n\t\tuserclicks smallint(5) NOT NULL,\n\t\turlfrom text NOT NULL,\n\t\ttype varchar(60) DEFAULT &#039;vue&#039; NOT NULL,\n\t\tlanguage varchar(60) NOT NULL,\n\t\tUNIQUE KEY id (id)\n\t\t) $charset_collate;&quot;;\n\trequire_once( ABSPATH . &#039;wp-admin\/includes\/upgrade.php&#039; );\n\tdbDelta( $sql );\n}\t\nadd_action( &#039;init&#039;, &#039;database_wooclassementstats&#039;);<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Here&#8217;s our table within <strong>phpMyAdmin.<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n\n\t<div  class=\"wpb_single_image wpb_content_element vc_align_left wpb_content_element\">\n\t\t\n\t\t<figure class=\"wpb_wrapper vc_figure\">\n\t\t\t<div class=\"vc_single_image-wrapper   vc_box_border_grey\"><img decoding=\"async\" width=\"1917\" height=\"448\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin.png\" class=\"vc_single_image-img attachment-full\" alt=\"Possible web outage due to WPML\" title=\"Creating tables in phpMyAdmin\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin.png 1917w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin-600x140.png 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin-300x70.png 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin-1024x239.png 1024w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin-768x179.png 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin-1536x359.png 1536w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Creation-de-table-dans-phpMyAdmin-1320x308.png 1320w\" sizes=\"(max-width: 1917px) 100vw, 1917px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>As you can see there are multiple columns in our WordPress table.<\/p>\n<p>First, change the name of the table, <strong>wooclassementstats<\/strong> to the naming convention of <strong>your table<\/strong>.<\/p>\n<p>You&#8217;ll also need to replace the columns&#8217; names and adapting them to the data you&#8217;re looking for.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading vc_custom_1666357967792\" >Adding Formidable fields data<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>For that we&#8217;re gonna need the <a href=\"https:\/\/formidableforms.com\/knowledgebase\/formidable-hooks\/\" target=\"_blank\" rel=\"noopener\"><strong>hook Formidable Form<\/strong><\/a> called <a href=\"https:\/\/formidableforms.com\/knowledgebase\/frm_after_create_entry\/\" target=\"_blank\" rel=\"noopener\">frm_after_create_entry<\/a><\/p>\n<p>Within our hook, we will add a condition where it&#8217;ll need to fetch data from the form according to the specific form ID.<\/p>\n<p>The <strong>$values<\/strong> variable includes all the data fetched from the form. Change the <strong>columns&#8217; names<\/strong> and <strong>IDs of the matching fields<\/strong> for each field.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-9406487\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-9406487\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">add_action(&#039;frm_after_create_entry&#039;, &#039;copy_into_my_table&#039;, 20, 2);\nfunction copy_into_my_table($entry_id, $form_id){ \n  if($form_id == 2){ \/\/change 4 to the form id of the form to copy\n    global $wpdb;\n    $values = array(\n    &#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][24], \n    &#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][25], \n    &#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][22],\n    &#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][21],\n    &#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][26],\n    &#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][23],\n    &#039;col_name&#039;         =&gt; &#039;&#039;,\n    &#039;col_name&#039;         =&gt; &#039;&#039;, \n    &#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][27],\n    );\n    \/\/replace 25 and 26 with the field ids of the Formidable form. Change col_name to the column names in your table\n    $wpdb-&gt;insert(&#039;wpeo_LDAAnalytics&#039;, $values); \n  }\n}<\/pre><\/div><h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading vc_custom_1666357768117\" >For Multi-sites websites<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>If you have a multisite, first thing you&#8217;ll need to do is make sure all forms have their own unique IDs. You will need the <a href=\"https:\/\/developer.wordpress.org\/reference\/functions\/switch_to_blog\/\" target=\"_blank\" rel=\"noopener\"><strong>switch_to_blog<\/strong><\/a> function.<\/p>\n<p>Our form&#8217;s condition will need to be set between <strong>switch_to_blog<\/strong> and <strong>restore_current_blog();<\/strong> which will respect the blog&#8217;s query.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-12\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\"><div id=\"ts-enlighterjs-container-8945943\" class=\"ts-enlighterjs-container-single-enabled  \" style=\"width: 100%;  margin-top: 0px; margin-bottom: 0px;\" data-enlighter-doubleclick=\"true\" data-enlighter-windowbutton=\"true\" data-enlighter-windowtext=\"New Window\" data-enlighter-rawbutton=\"true\" data-enlighter-rawtext=\"RAW Code\" data-enlighter-infobutton=\"false\" data-enlighter-infotext=\"EnlighterJS\" data-enlighter-indent=\"2\"><pre id=\"ts-enlighterjs-pre-8945943\" class=\"\" style=\"white-space: pre-wrap; height: 100%; margin: 0; padding: 0;\" data-enlighter-language=\"php\" data-enlighter-theme=\"enlighter\" data-enlighter-group=\"\" data-enlighter-title=\"\" data-enlighter-linenumbers=\"true\" data-enlighter-lineoffset=\"1\" data-enlighter-highlight=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Insert datas after create entry from Form  \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\n\nadd_action(&#039;frm_after_create_entry&#039;, &#039;copy_into_my_table&#039;, 20, 2);\nfunction copy_into_my_table($entry_id, $form_id){ \n\tswitch_to_blog(2);\n\tif($form_id == 2){ \/\/change 4 to the form id of the form to copy\n\t\tglobal $wpdb;\n\t\t$values = array(\n\t\t&#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][24], \n\t\t&#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][25], \n\t\t&#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][22],\n\t\t&#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][21],\n\t\t&#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][26],\n\t\t&#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][23],\n\t\t&#039;col_name&#039;         =&gt; &#039;&#039;,\n\t\t&#039;col_name&#039;         =&gt; &#039;&#039;, \n\t\t&#039;col_name&#039;         =&gt; $_POST[&#039;item_meta&#039;][27],\n\t\t);\n\t\t\/\/replace 25 and 26 with the field ids of the Formidable form. Change col_name to the column names in your table\n\t\t$wpdb-&gt;insert(&#039;wpeo_LDAAnalytics&#039;, $values); \n\t}\n\trestore_current_blog();\n}<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>In conclusion, injecting data in a WordPress table will allow you to have duplicates of the data or offering stats to your clients.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"You want to create a new data entry in a custom Wordpress table from a Formidable form? Let's say you want to create a table in order to get data<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/wordpress-table-formidable-form-data\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":6853,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[],"class_list":["post-6864","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/users\/81"}],"replies":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/comments?post=6864"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6864\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/6853"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}