{"id":6750,"date":"2022-10-04T17:16:54","date_gmt":"2022-10-04T21:16:54","guid":{"rendered":"https:\/\/themespress.ca\/?p=6750"},"modified":"2022-10-09T08:01:00","modified_gmt":"2022-10-09T12:01:00","slug":"selection-field-formidable-form","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/selection-field-formidable-form\/","title":{"rendered":"Completing a Selection Field &#8211; Formidable Form"},"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>With this tutorial we will show you how to complete a selection field in Formidable Form. <a href=\"https:\/\/shareasale.com\/r.cfm?b=841990&amp;u=1476870&amp;m=64739&amp;urllink=&amp;afftrack=\" target=\"_blank\" rel=\"noopener\"><strong>Formidable form<\/strong><\/a> is one of the best form creation plugin available.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Create a form and add a selection field<\/h2>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>You can create a form, configure it and add it where you want it on your WordPress website.<\/p>\n<p>Once the form is configured, you can add the necessary fields. <strong>(Note that some fields are only available in the PRO version)<\/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=\"1884\" height=\"706\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress.png\" class=\"vc_single_image-img attachment-full\" alt=\"\" title=\"Screenshot 2022-10-04 at 16-05-08 Formidable Formulaires \u2039 Viamultimedia H\u00e9bergement Web \u2014 WordPress\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress.png 1884w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-600x225.png 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-300x112.png 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-1024x384.png 1024w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-768x288.png 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-1536x576.png 1536w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-05-08-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-1320x495.png 1320w\" sizes=\"(max-width: 1884px) 100vw, 1884px\" \/><\/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>For this example, we will add a custom selection field.<\/p>\n<p>By clicking on our field, <strong>we can see its ID on the right-hand side<\/strong>. This ID is important as we&#8217;ll use it for certain queries.<\/p>\n<div id=\"malwarebytes-root\"><\/div>\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=\"1333\" height=\"95\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-17-20-16-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress.png\" class=\"vc_single_image-img attachment-full\" alt=\"\" title=\"Screenshot 2022-10-04 at 17-20-16 Formidable Formulaires \u2039 Viamultimedia H\u00e9bergement Web \u2014 WordPress\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-17-20-16-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress.png 1333w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-17-20-16-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-600x43.png 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-17-20-16-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-300x21.png 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-17-20-16-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-1024x73.png 1024w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-17-20-16-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-768x55.png 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-17-20-16-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-1320x94.png 1320w\" sizes=\"(max-width: 1333px) 100vw, 1333px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n<h2 style=\"text-align: left\" class=\"vc_custom_heading vc_do_custom_heading\" >Dynamically completing the selection field - our posts<\/h2><\/div><\/div><\/div><\/div><div class=\"vc_row wpb_row vc_row-fluid\"><div class=\"wpb_column vc_column_container vc_col-sm-8\"><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>For this query, we will create a <a href=\"https:\/\/formidableforms.com\/knowledgebase\/frm_setup_new_fields_vars\/\" target=\"_blank\" rel=\"noopener\"><strong>frm_setup_new_fields_vars<\/strong><\/a> function from Formidable Form.<\/p>\n<p>To edit resulting values, we will add the <a href=\"https:\/\/formidableforms.com\/knowledgebase\/frm_setup_new_fields_vars\/\" target=\"_blank\" rel=\"noopener\"><strong>frm_setup_new_fields_vars<\/strong><\/a> filter.<\/p>\n<p>In our function, we will fetch our ID (<span class=\"nu0\">72<\/span>) of the field where the results will be displayed; i.e. our posts.<\/p>\n<p>In our function, we created a default label for our selection. (For our example, we&#8217;re using <strong>Select a question<\/strong>)<\/p>\n<p><strong>label => &#8220;Select a question&#8221;<\/strong><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><div class=\"wpb_column vc_column_container vc_col-sm-4\"><div class=\"vc_column-inner\"><div class=\"wpb_wrapper\">\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=\"432\" height=\"658\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-57-23-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress.png\" class=\"vc_single_image-img attachment-full\" alt=\"Articles WordPress dans un champ s\u00e9lection Formidable Form\" title=\"Screenshot 2022-10-04 at 16-57-23 Formidable Formulaires \u2039 Viamultimedia H\u00e9bergement Web \u2014 WordPress\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-57-23-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress.png 432w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-57-23-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-416x634.png 416w, https:\/\/themespress.ca\/wp-content\/uploads\/2022\/10\/Screenshot-2022-10-04-at-16-57-23-Formidable-Formulaires-\u2039-Viamultimedia-Hebergement-Web-\u2014-WordPress-197x300.png 197w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/div>\n\t\t<\/figure>\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-2945858\" 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-2945858\" 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_filter(&#039;frm_setup_new_fields_vars&#039;, &#039;themespress_select_field_function&#039;, 20, 2);\nadd_filter(&#039;frm_setup_edit_fields_vars&#039;, &#039;themespress_select_field_function&#039;, 20, 2);\n\nfunction themespress_select_field_function($values, $field){\n\n\tif($field-&gt;id == 72){\n\t\t$arrayPositions = array();\n\t\t$pushobj = array(\n\t\t\tvalue =&gt; &quot;&quot;,\n\t\t\tlabel =&gt; &quot;S&eacute;lectionnez une question&quot;\n\t\t);\n\t\tarray_push($arrayPositions, $pushobj);\n\t\t$positionQuery = new WP_Query( array( &#039;post_type&#039; =&gt; &#039;questions&#039;, &#039;posts_per_page&#039; =&gt; -1, &#039;orderby&#039; =&gt; &quot;menu_order&quot;, &#039;order&#039; =&gt; &quot;ASC&quot;) );\n\t\tif ( $positionQuery-&gt;have_posts() ) {\n\t\t\twhile ( $positionQuery-&gt;have_posts() ) {\n\t\t\t\t$positionQuery-&gt;the_post();\n\t\t\t\t$pushobj = array(\n\t\t\t\t\tvalue =&gt; get_the_title(),\n\t\t\t\t\tlabel =&gt; get_the_title()\n\t\t\t\t);\n\t\t\t\tarray_push($arrayPositions, $pushobj);\n\t\t\t}\n\t\t\twp_reset_postdata();\n\t\t}\n\n\t   \t$values[&#039;options&#039;] = $arrayPositions;\n\t}\n\treturn $values;\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>And finally, in your query, you can adapt whether you want to display posts or pages.<\/p>\n<div id=\"malwarebytes-root\"><\/div>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-2233049\" 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-2233049\" 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=\"\">$positionQuery = new WP_Query( array( &#039;post_type&#039; =&gt; &#039;questions&#039;, &#039;posts_per_page&#039; =&gt; -1, &#039;orderby&#039; =&gt; &quot;menu_order&quot;, &#039;order&#039; =&gt; &quot;ASC&quot;) );<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element read-more\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p><a href=\"https:\/\/themespress.ca\/?s=Formidable+form\" target=\"_blank\" rel=\"noopener\">Formidable form posts<\/a><\/p>\n\n\t\t<\/div>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"With this tutorial we will show you how to complete a selection field in Formidable Form. Formidable form is one of the best form creation plugin available. Create a form<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/selection-field-formidable-form\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":6696,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[],"class_list":["post-6750","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\/6750","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=6750"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/6750\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/6696"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=6750"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=6750"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=6750"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}