{"id":4208,"date":"2019-08-08T11:45:04","date_gmt":"2019-08-08T15:45:04","guid":{"rendered":"https:\/\/themespress.ca\/?p=4208"},"modified":"2021-11-18T06:44:06","modified_gmt":"2021-11-18T11:44:06","slug":"create-a-user-status-with-formidable-form","status":"publish","type":"post","link":"https:\/\/themespress.ca\/en\/create-a-user-status-with-formidable-form\/","title":{"rendered":"Create a User Status With 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 create a function that will allow users to chose their roles based on a pre-determined list and subsequently create a new role for the user.<\/p>\n<p>First we need to create our user role. In this example, we want to add a <strong>Doctor role<\/strong>, <strong>Pharmacist role<\/strong> and a <strong>Nurse role<\/strong>; via the functions.php or another file.<\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-5148988\" 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-5148988\" 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 User Role \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \nfunction medecin_new_role() {  \n \n    \/\/add the new user role\n    add_role(\n        &#039;medecin&#039;,\n        &#039;Medecin&#039;,\n        array(\n            &#039;read&#039;         =&amp;gt; true,\n            &#039;delete_posts&#039; =&amp;gt; false\n        )\n    );\n \n}\nadd_action(&#039;admin_init&#039;, &#039;medecin_new_role&#039;);\n \nfunction pharmacien_new_role() {  \n \n    \/\/add the new user role\n    add_role(\n        &#039;pharmacien&#039;,\n        &#039;Pharmacien&#039;,\n        array(\n            &#039;read&#039;         =&amp;gt; true,\n            &#039;delete_posts&#039; =&amp;gt; false\n        )\n    );\n \n}\nadd_action(&#039;admin_init&#039;, &#039;pharmacien_new_role&#039;);\n \nfunction infirmiere_new_role() {  \n \n    \/\/add the new user role\n    add_role(\n        &#039;infirmiere&#039;,\n        &#039;Infirmi&egrave;r(e)&#039;,\n        array(\n            &#039;read&#039;         =&amp;gt; true,\n            &#039;delete_posts&#039; =&amp;gt; false\n        )\n    );\n \n}\nadd_action(&#039;admin_init&#039;, &#039;infirmiere_new_role&#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>We can now validate a user&#8217;s profil and confirm that our three newly added roles are listed. Then we have to create a form that will allow someone to create their new user with the <strong><a href=\"https:\/\/formidableforms.com\/knowledgebase\/user-registration\/\" target=\"_blank\" rel=\"noopener noreferrer\">formidable User Registration add-on<\/a><\/strong>.<\/p>\n<p>Simply create a form with the necessary fields such as first\/last name, email, etc&#8230; For this to work, make sure to create a <strong>Statut<\/strong> field (you can name it however you see fit). For this field, make sure it&#8217;s a Radio button with the three roles we mentioned above for the example: <\/p>\n\n\t\t<\/div>\n\t<\/div>\n<div class=\"vc_row wpb_row vc_inner vc_row-fluid\"><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=\"149\" height=\"300\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/options-roles-1-149x300.jpg\" class=\"vc_single_image-img attachment-medium\" alt=\"\" title=\"options-roles\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/options-roles-1-149x300.jpg 149w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/options-roles-1-416x840.jpg 416w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/options-roles-1.jpg 425w\" sizes=\"(max-width: 149px) 100vw, 149px\" \/><\/div>\n\t\t<\/figure>\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=\"300\" height=\"58\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/boutons-1-300x58.jpg\" class=\"vc_single_image-img attachment-medium\" alt=\"\" title=\"boutons\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/boutons-1-300x58.jpg 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/boutons-1-416x81.jpg 416w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/boutons-1.jpg 510w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/div>\n\t\t<\/figure>\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=\"300\" height=\"142\" src=\"https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1-300x142.jpg\" class=\"vc_single_image-img attachment-medium\" alt=\"\" title=\"user-registration\" srcset=\"https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1-300x142.jpg 300w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1-600x284.jpg 600w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1-1024x485.jpg 1024w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1-768x364.jpg 768w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1-1536x728.jpg 1536w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1-1320x625.jpg 1320w, https:\/\/themespress.ca\/wp-content\/uploads\/2019\/08\/user-registration-1.jpg 1925w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/div>\n\t\t<\/figure>\n\t<\/div>\n<\/div><\/div><\/div><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p>Now we will need to go into the form&#8217;s settings under Actions\/Notifications to add a user registration function. Fill out the necessary and leave author by default.<\/p>\n<p>For example:<\/p>\n<p>Voici la fonction qui donne les conditions n\u00e9cessaires d\u2019attribuer le bon r\u00f4le utilisateur au moment de son inscription et de son choix de r\u00f4le. Here&#8217;s the function that will return the necessary conditions in order to assign the right role to the user when signing up and choosing their role. <\/p>\n<p>We change the IDs by the appropriate IDs of your form and field. <\/p>\n<ul>\n<li>ID 190 is the field ID.<\/li>\n<li>ID 6 is the form ID.<\/li>\n<\/ul>\n\n\t\t<\/div>\n\t<\/div>\n<div id=\"ts-enlighterjs-container-8424816\" 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-8424816\" 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=\"\">\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ Formidable form attribute user r&ocirc;le \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ \nfunction statut_new_role($user_role, $atts){\n  extract($atts);\n  if($form-&amp;gt;id == 6){ \/\/ WSIS: change this to your form ID\n    if($_POST[&#039;item_meta&#039;][190] == &#039;medecin&#039;) \/\/change 125 to the ID of your field and &#039;Author&#039; to the value of your radio button WSIS: or single checkbox\n    $user_role = &#039;medecin&#039;; \/\/ WSIS: rolename\n\tif($_POST[&#039;item_meta&#039;][190] == &#039;infirmiere&#039;) \/\/change 125 to the ID of your field and &#039;Author&#039; to the value of your radio button WSIS: or single checkbox\n    $user_role = &#039;infirmiere&#039;; \/\/ WSIS: rolename\n\tif($_POST[&#039;item_meta&#039;][190] == &#039;pharmacien&#039;) \/\/change 125 to the ID of your field and &#039;Author&#039; to the value of your radio button WSIS: or single checkbox\n    $user_role = &#039;pharmacien&#039;; \/\/ WSIS: rolename\n  }\n  return $user_role;\n}\n \nadd_filter(&#039;frmreg_new_role&#039;, &#039;statut_new_role&#039;, 10, 2);<\/pre><\/div>\n\t<div class=\"wpb_text_column wpb_content_element\" >\n\t\t<div class=\"wpb_wrapper\">\n\t\t\t<p> Finally, you will need to test the form to confirm that it will assign the selected tole to your user. Make sure that all data are displayed individually in your form and that in your conditional function, it displays the proper value assigned to each role.<\/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 create a function that will allow users to chose their roles based on a pre-determined list and subsequently create a new<div class=\"read-more\"><a class=\"btn button-secondary\" href=\"https:\/\/themespress.ca\/en\/create-a-user-status-with-formidable-form\/\">Read More<\/a><\/div>","protected":false},"author":81,"featured_media":4945,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[283],"tags":[351,313],"class_list":["post-4208","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-forms","tag-plugins"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4208","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=4208"}],"version-history":[{"count":0,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/posts\/4208\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media\/4945"}],"wp:attachment":[{"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/media?parent=4208"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/categories?post=4208"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/themespress.ca\/en\/wp-json\/wp\/v2\/tags?post=4208"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}