fudgite
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Plugins
In reply to: [Caldera Forms - More Than Contact Forms] Math with dates?You also have to change the
Caldera_Forms::run_calculation()function incaldera-forms/classes/core.php(~1017)Search for this : (~1049)
if (is_array($entry_value)) { $number = floatval(array_sum($entry_value)); } else { $number = floatval($entry_value); }To change it for :
if($cfg['type'] == 'date_picker') { $number = empty($entry_value) ? 0 : (strtotime($entry_value) / (3600 * 24)); } else { if (is_array($entry_value)) { $number = floatval(array_sum($entry_value)); } else { $number = floatval($entry_value); } }Forked it in with the fix my Github :
https://github.com/pboissonneault/Caldera-FormsNevermind, “my fault”..
Why do you need to use
Caldera_Forms::run_calculation()server side when you already have the value in the$_POSTvariable ?Forum: Plugins
In reply to: [Caldera Forms - More Than Contact Forms] Math with dates?You’ll need to update the
caldera-forms/fields/calculation/field.phpfile.Change this line (~62)
$binds_vars[] = $fid . " = parseFloat( $('[data-field=\"" . $fid . "\"]').is(':checkbox') ? checked_total_" . $field_base_id . "($('[data-field=\"" . $fid . "\"]:checked')) : $('[data-field=\"" . $fid . "\"]').is(':radio') ? $('[data-field=\"" . $fid . "\"]:checked').val() : $('[data-field=\"" . $fid . "\"]').val() ) || 0 ";With this :
if($cfg['type'] == 'date_picker') { $binds_vars[] = $fid." = ((new Date( $('[data-field=\"".$fid."\"]').val() )) / (1000 * 3600 * 24))"; } else { $binds_vars[] = $fid . " = parseFloat( $('[data-field=\"" . $fid . "\"]').is(':checkbox') ? checked_total_" . $field_base_id . "($('[data-field=\"" . $fid . "\"]:checked')) : $('[data-field=\"" . $fid . "\"]').is(':radio') ? $('[data-field=\"" . $fid . "\"]:checked').val() : $('[data-field=\"" . $fid . "\"]').val() ) || 0 "; }This will convert your date to a number of days. So when you substract dates, you’ll get number of days between them.
Viewing 3 replies - 1 through 3 (of 3 total)