I’m just starting out and trying to figure out how to use conditional functions in gravity forms.
I should do a date change based on a value of a select field
this is the function i have done so far but i can’t get it to work
//id form= 2
//field of select box= 8
//target date field= 13
//source date field= 7
add_filter( 'gform_pre_render', 'set_conditional_logic' );
add_filter( 'gform_pre_process', 'set_conditional_logic' );
function set_conditional_logic( $form ) {
if ( $form['id'] !== 2 ) {
return $form;
}
$duration = '';
foreach ( $form['fields'] as &$field ) {
if ( $field->id == 8 ) {
$duration = $field['value'];
}
}
if ( $duration == '12' )
{
new GW_Populate_Date( array(
'form_id' => 2,
'target_field_id' => 13,
'source_field_id' => 7,
'modifier' => '+1 year'
) );}
else
{
new GW_Populate_Date( array(
'form_id' => 2,
'target_field_id' => 13,
'source_field_id' => 7,
'modifier' => '+2 year'
) );
}
return $form;
}