I ended up doing this in functions.php
add_action("gform_pre_submission", "pre_submission_handler");
function pre_submission_handler($form_meta){
if($form_meta["id"] == '1'){
$total_value = 0;
foreach($form_meta["fields"] as $field){
$value = $_POST["input_" . $field["id"]];
$total_value = $total_value + $value;
}
$_POST["input_8"] = $total_value;
}
return $form;
}
I'm sure there's a more elegant way, but, this worked.
input_8 is a hidden field to store the cumulative value.
I turned on 'values' and each multiple choice answer got assigned the point value I wanted.
I'm posting this here in the hopes that it can 1) help someone else, and 2) others can help me improve on this :)
What I'm still not sure on is how I can retrieve the hidden field value easily? Or, if there's any easy way to use a querystring to selectively hide/show the "results" on the confirmation page.
I guess what would be nice would be to have some sort of scripting ability on the notification page so that I can do something like [if input_8 >= 2 || input_8 <= 4 then....]
Anyways, just a thought.
David
Posted 13 years ago on Sunday March 6, 2011 |
Permalink