Hi All,
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:
- Change 25 to the ID of the field you want to insert the value into
- Change SUM(Shares_Remaining) to the name (or sum of) the column you wish to search
- Change UserSummaryByYear to the name of the db table
- This example checks the UserSummaryByYear table for the 'user_name' column and compares it to the users WordPress login. Edit as required.
Thanks
Chris