Hi there
I am calculating the average of submitted forms using the following code with three conditions:
- Field ID > 26
- Field value > input
- Time range
Everything is working correctly. For example, using the shortcode below, I am calculating the average of forms submitted within a specified time range where the value in field number 50 matches a specified input value.
Now, I need to add another condition or filter to it so that we can filter the values based on another field in the form, which has ID 50 and contains people's email addresses, so that each person only sees the average data related to themselves and not all submitted forms.
Document Link:
https://formidableforms.com/knowledgebase/add-field-totals-and-statistics/#kb-percentage-of-a-specific-field-value
My Shortcode:
[frm-percent id=26 value="input"]
My Code is:
add_shortcode('frm-percent', 'frm_stats_percent');
function frm_stats_percent($atts){
// Start date: 10 days after the first day of the current month
$first_day_of_month = date('Y-m-01 00:00:00');
$start_date = date('Y-m-d H:i:s', strtotime($first_day_of_month . ' +10 days')); // End date: Current date and time
$end_date = wp_date("Y-m-d H:i:s", null ); $defaults = array(
'id' => false,
'user_id' => 'false',
'value' => false,
//'round' => 100,
'limit' => '',
'created_at_greater_than_or_equal_to' => $start_date,
'created_at_less_than_or_equal_to' => $end_date
);
extract(shortcode_atts($defaults, $atts));
var_dump ($defaults); // For debugging, display the calculated dates
echo 'Start Date: ' . $start_date . '<br>';
echo 'End Date: ' . $end_date . '<br>'; if (!$id) return; $type = 'count'; // Count the number of entries that match the target value
$value_count = FrmProStatisticsController::stats_shortcode(compact(
'created_at_greater_than_or_equal_to',
'created_at_less_than_or_equal_to',
'id',
'type',
'value',
'limit'
)); echo 'Total Count Based On Target Value Count: ' . $value_count . '<br>'; // Count the total number of entries based on the target field
$total_count = FrmProStatisticsController::stats_shortcode(compact(
'created_at_greater_than_or_equal_to',
'created_at_less_than_or_equal_to',
'id',
'type',
'limit'
)); echo 'Total Count Based on Target Field:' . $total_count . '<br>'; // Return the percentage of entries that match the target value
return round((($value_count / $total_count) * 100));
}
Please login or Register to submit your answer