spivurno
1/17/2014 - 8:49 PM

Gravity Forms: Example of conditionally requiring a field based on the value of another field.

Gravity Forms: Example of conditionally requiring a field based on the value of another field.

<?php
/**
 * Gravity Forms: Example of conditionally requiring a field based on the value of another field.
 */
add_filter( 'gform_pre_render', 'gw_conditional_requirement' );
add_filter( 'gform_pre_validation', 'gw_conditional_requirement' );
function gw_conditional_requirement( $form ) {

    $value = rgpost( 'input_2' );
    if( $value == 'no' )
        return $form;

    foreach( $form['fields'] as &$field ) {

        if( $field['id'] == 1 ) {
            $field['isRequired'] = true;
        }

    }

    return $form;
}