• Skip to main content
  • Skip to primary sidebar

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network

FormidablePro DropDown from any Table

November 15, 2014 By Victor M. Font Jr.

Formidable Pro LogoMake no mistake about it, Formidable Pro is my favorite form building tool. Why? One of the primary reasons is the unparalleled flexibility provided by its API. Formidable Pro offers developers many hooks that allow you to easily take advantage of built-in core WordPress functionality.

To illustrate, in the exemplar below I am accessing the $wpdb object to populate a Formidable Pro dropdown with custom values pulled from a third party membership management table. The requirement is from a form built for the North Carolina Executive Roundtable (NCER). The North Carolina Executive Roundtable is a professional association of senior-level executives located in Raleigh, NC. Membership is by invitation only. The site's forms require members to submit their name. Of course, there are several ways to do this. We could have members directly enter their name in a text field, which can lead to inconsistencies later on if generating reports, or we could have members select their name from a drop down built from membership details.

Extracting membership details may not be an easy task however. Members come and go and memberships expire if dues aren't paid. As a result, the membership list is dynamic, which means any dropdown built from a membership tables needs to be dynamic. Membership plugins like S2member use the wp_users table to store membership details. Additional attributes other than the core user information is stored in wp_user_meta, which requires a SQL join to extract all appropriate details. Other plugins like WP eMember from Tips and Tricks HQ use their own tables to store member details.

In the former situation, it's appropriate to access the user details with WP User Query. In the latter, the NCER website uses WP eMember as its membership management tool, so it is appropriate to use the $wpdb object. To make this all work with Formidable Pro, we'll be accessing the frm_setup_new_fields_vars and frm_setup_edit_fields_vars hooks.

To get started, copy the code below to your functions.php file. Change the SQL in the line 10 that begins with $the_Result with your own custom query. Since you are using custom code, make sure you've tested it thoroughly in PhpMyAdmin, MySQL Workbench or another of your favorite SQL tools. Make sure you receive the expected results before adding the custom SQL query to your code. This is important because the Formidable Pro support agreement does not permit their excellent support team to help with custom code. So it is incumbent upon you to test, test, test and test again to make sure your custom code is right in every respect.

//populate the member dropdown field for nomination and member-advocate event forms
// data comes from wp_wp_eMember_members_tbl
add_filter(frm_setup_new_fields_vars, frm_populate_member, 20, 2);
add_filter(frm_setup_edit_fields_vars, frm_populate_member, 20, 2); //use this function on edit too

function frm_populate_member($values, $field){
    if($field->id == 732 || $field->id == 733){ //replace 732 and 733 with the IDs of the fields to populate
        global $wpdb;
        //the Query
        $the_Result = $wpdb->get_results( "SELECT concat_ws(', ', last_name, first_name) as display_name FROM wp_database.wp_wp_eMember_members_tbl where account_state = 'active' order by last_name, first_name;" );

        unset($values['options']); //break the binding of any existing content in the values array

        $values['options'] = array(); //remove this line if you are using a checkbox or radio button field
        $values['options'][]="";

        //the Loop
        if(! empty($the_Result)){
            foreach($the_Result as $a_user){
                $values['options'][]=$a_user->display_name;
                $values['use_key'] = false;
            }
        }
    //$values['use_key'] = true; //this will set the field to save the post ID instead of post title
    }
return $values;
}

If you run into issues, please feel free to contact me. In most cases, I'll be able to help solve your problem in a few minutes. If it takes longer than a quick fix, my consulting rates are reasonable.

  • 10shares
  • Facebook0
  • Twitter0
  • Pinterest0
  • LinkedIn10
  • Print
  • SMS0

Filed Under: Code Snippet, Computers and Internet, Formidable Forms, How To, PHP, Plugins, Programming, Tutorial, WordPress Tagged With: Code Snippet, Computers and Internet, Formidable Forms, How To, PHP, Plugins, Programming, Tutorial, WordPress

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Primary Sidebar

Shopping Cart

Books

  • Winning With WordPress Basics 2nd Edition Winning With WordPress Basics 2nd Edition $19.95
  • Ultimate Guide to the SDLC front cover The Ultimate Guide to the SDLC
    Rated 5.00 out of 5
    $74.95

Recent Articles

  • Modern Scam Defense: How Consumers and Businesses Can Recognize and Stop Email, Phone, and Text Fraud
  • How to Write a PRD So Dense It’s Technically a Novel
  • Top 5 Plugin Names That Scare Our Legal Department
  • When Agile Meets Our 3-Year Waterfall Roadmap: A Love Story
  • Why Our Enterprise Needs 27 Stakeholders to Approve a Button Color Change

Top 10 Article Categories

Best Practice Code Snippet Computers and Internet Genesis How To Leadership Programming Servant Leadership Tutorial WordPress

 
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.