Skip to content

Instantly share code, notes, and snippets.

@speedguy
Last active February 6, 2023 23:13
Show Gist options
  • Select an option

  • Save speedguy/672dc22f2e30c2b21ced97a4dcc1e338 to your computer and use it in GitHub Desktop.

Select an option

Save speedguy/672dc22f2e30c2b21ced97a4dcc1e338 to your computer and use it in GitHub Desktop.
WP Forms Calculator Demo
add_filter ('wpforms_frontend_confirmation_message', 'restrict_form_formula', 10, 2);
function restrict_form_formula($confirmation_message, $form_data) {
if ($form_data['id'] == 642) { /* This number is form id - so that we only process the results for this form */
$monthly_recurring = $_POST['wpforms']['fields'][1]; /* The id for the field you want to use in calculation */
$ad_spent_month = $_POST['wpforms']['fields'][2]; /* The id for the field you want to use in calculation */
$total_budget = $_POST['wpforms']['fields'][3]; /* The id for the field you want to use in calculation */
$calculation = ($monthly_recurring * $ad_spent_month) / $total_budget;
return $calculation;
}
else {
return $confirmation_message;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment