This snippet can be used to get a value from another database table and insert it as the default value of a form field.

// Get Remaining Shares
add_filter('frm_get_default_value', 'my_custom_default_value', 10, 2);
function my_custom_default_value($new_value, $field){
if($field->id == 25){ //change 25 to the ID of the field
global $wpdb;
$user = wp_get_current_user();
$new_value = $wpdb->get_var("SELECT SUM(Shares_Remaining) FROM UserSummaryByYear WHERE user_name='$user->user_login'");
}
return $new_value;
}

Notes:

  1. Change 25 to the ID of the field you want to insert the value into
  2. Change SUM(Shares_Remaining) to the name (or sum of) the column you wish to search
  3. Change UserSummaryByYear to the name of the db table
  4. This example checks the UserSummaryByYear table for the ‘user_name’ column and compares it to the users WordPress login. Edit as required.

Still have questions?

Still have questions or not sure where to start? Use our quick contact to ask us a question.

Start Planning

If you’re ready to get started click here to complete our Project Planner.

You may also like…

FormidableTutorials
26 Mar 2019

Formidable Forms: File Upload Folder

Formidable Forms: Changing the File Upload Folder The Problem: You may want to change the folder that files will be…
FormidableTutorials
26 Mar 2019

Formidable Forms: Create an Invoicing system

Formidable Forms: Create an Invoicing system Here’s a guide on how to use Formidable Pro to create an invoicing system…
FormidableTutorials
26 Mar 2019

Share a form entry between users

Formidable Forms: Create a shared entry & view The Problem In some cases you may need to build a form…