I modified the module to allow for a field to have multiple options and be summed. I tested this with checkboxes, select and multiselects and was able to get the desired result.
Previously, I would get a validation error that said "(component_name) amount is invalid" because it was not expecting an array.
Here is my change. Bear with me, not sure how to create a patch in git.
function _webform_pay_component_value($node, $component, $values) {
$parent_keys = webform_component_parent_keys($node, $component);
foreach ($parent_keys as $form_key) {
if (isset($values[$form_key]) && !is_array($values[$form_key])) {
$values = $values[$form_key];
} elseif (isset($values[$form_key]) && is_array($values[$form_key])) {
foreach ($values[$form_key] as $field_amount => $field_label) {
if (is_numeric($field_amount)) {
$total += $field_amount;
}
}
$values = $total;
} else {
$values = FALSE;
break;
}
}
return $values;
}
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | webform_pay_checkboxes.patch | 1.74 KB | quicksketch |
| #7 | patch-1214884-5.patch | 844 bytes | kevinquillen |
| #6 | patchreroll-1214884-4.patch | 819 bytes | kevinquillen |
| #5 | patch_reroll-#1214884-4.patch | 819 bytes | kevinquillen |
| #1 | multivaluefield-1124884-1.patch | 871 bytes | kevinquillen |
Comments
Comment #1
kevinquillen commentedAttaching my first ever git patch...
Comment #2
kevinquillen commentedComment #3
kevinquillen commentedRerolling..
Comment #4
kevinquillen commentedRerolling..
Comment #5
kevinquillen commentedSorry for the dupes. It seems when I use the Git Instructions on the module I receive an old version of Webform Pay. Getting the hang of it now I think.
Comment #6
kevinquillen commentedPrevious upload goes to Page Not Found..
Comment #7
kevinquillen commentedHad to add != FALSE after is_numeric check... looks like if you don't pick any options of a checkbox field, it passes the array of allowed values but changes the label to FALSE for each one.
Is that expected behavior of webform? Just wondering if it may have been something I did instead.
Comment #8
quicksketchThanks Kevin, I modified your patch to make it so that the _webform_pay_component_value() function is unaffected, since that function is also used on things that aren't the "price" totals at all. Otherwise we might do strange things like accidentally adding up a users address fields together. This patch adds support for checkboxes/multi-select fields and adds up the totals properly.