add_filter( 'gform_pre_submission_18', 'time_calculation' );
function time_calculation($form){
$getvalue = rgpost("input_18_5_1");
if (!empty($getvalue)){
echo $getvalue;}
else echo ("no value");
}
I am trying to do time calculation when user hits submit, but before an entry is made. Following guides and documentations online, rgpost() is what I am looking for. But it did not return the field value, the above snippet echos no value.
The field value I try to grab is the Time Widget in 12 hour format, input_18_5_1 is the hour input.
I have tried to use the number widget’s calculation function, but the duration did not show up in real time as user make changes.
Rather than using echo for debugging, I would recommend you to enable logging.
That would allow you to add custom logging statements to your code. For example to dump the full contents of $_POST to the log to confirm if there’s really a value for that input or something wrong with rgpost:
Hello. I am not sure why your logging is not working. rgpost is definitely still working, and gform_pre_submission is still working.
The time values are submitted as an array for the field, so you can’t use rgpost alone. Try like this:
// form 18 only
add_filter( 'gform_pre_submission_18', 'time_calculation' );
function time_calculation( $form ){
// time field is ID 5
$time = rgpost("input_5");
$hour = $time[0];
$min = $time[1];
$ampm = $time[2];
if (!empty($hour)){
GFCommon::log_debug( __METHOD__ . "(): Hour is {$hour}." );
}
else {
GFCommon::log_debug( __METHOD__ . "(): Hour is not set." );
}
}
Thank you so much Chris! With this method, I was able to review the data in logging.
I believe the fix is you have defaulted input_5 for time field. I was using the ID from inspect element instead of name, will take note for future uses.