', esc_attr( $type ), esc_attr( $type ) ); switch ( $type ) { case 'field': /* * This settings block is for a field. */ // Define more data for this field. $fields_instance = $args['instance']; $field_id = absint( $field['id'] ); $field_name = "fields[{$field_id}]"; $groups_id = "wpforms-conditional-groups-fields-{$field_id}"; $action_selected = ! empty( $field['conditional_type'] ) ? $field['conditional_type'] : ''; $conditionals = ! empty( $field['conditionals'] ) ? $field['conditionals'] : array( array( array() ) ); $data_attrs = 'data-field-id="' . $field_id . '" '; $reference = $field_id; $enabled = isset( $field['conditional_logic'] ) ? $field['conditional_logic'] : false; $action_desc = ! empty( $args['action_desc'] ) ? $args['action_desc'] : esc_html__( 'this field if', 'wpforms-lite' ); if ( empty( $args['actions'] ) ) { $actions = array( 'show' => esc_attr__( 'Show', 'wpforms-lite' ), 'hide' => esc_attr__( 'Hide', 'wpforms-lite' ), ); } else { $actions = array_map( 'esc_attr', $args['actions'] ); } // Output Conditional Logic toggle checkbox field option. $fld = $fields_instance->field_element( 'checkbox', $field, array( 'slug' => 'conditional_logic', 'value' => $enabled, 'desc' => esc_html__( 'Enable conditional logic', 'wpforms-lite' ), 'tooltip' => '' . esc_html__( 'How to use Conditional Logic', 'wpforms-lite' ) . '', 'data' => array( 'name' => $field_name, 'actions' => $actions, 'action-desc' => esc_attr( $action_desc ), ), ), false ); $fields_instance->field_element( 'row', $field, array( 'slug' => 'conditional_logic', 'content' => $fld, 'class' => 'wpforms-conditionals-enable-toggle', ) ); // Prevent conditional logic from being applied to itself. if ( ! empty( $form_fields[ $field['id'] ] ) ) { unset( $form_fields[ $field['id'] ] ); } break; case 'panel': /* * This settings block is for something else - connections / notifications etc. */ $form_data = $args['form']; $action_desc = ! empty( $args['action_desc'] ) ? $args['action_desc'] : esc_html__( 'this connection if', 'wpforms-lite' ); if ( empty( $args['actions'] ) ) { $actions = array( 'go' => esc_attr__( 'Process', 'wpforms-lite' ), 'stop' => esc_attr__( 'Don\'t process', 'wpforms-lite' ), ); } else { $actions = array_map( 'esc_attr', $args['actions'] ); } // Below we do a bunch of voodoo to determine where this block // is located in the form builder - eg is it in a top level // setting or in a subsection, etc. if ( ! empty( $parent ) ) { if ( ! empty( $subsection ) ) { $field_name = sprintf( '%s[%s][%s]', $parent, $panel, $subsection ); $groups_id = sprintf( 'wpforms-conditional-groups-%s-%s-%s', $parent, $panel, $subsection ); $enabled = ! empty( $form_data[ $parent ][ $panel ][ $subsection ]['conditional_logic'] ) ? true : false; $action_selected = ! empty( $form_data[ $parent ][ $panel ][ $subsection ]['conditional_type'] ) ? $form_data[ $parent ][ $panel ][ $subsection ]['conditional_type'] : ''; $conditionals = ! empty( $form_data[ $parent ][ $panel ][ $subsection ]['conditionals'] ) ? $form_data[ $parent ][ $panel ][ $subsection ]['conditionals'] : array( array( array() ) ); } else { $field_name = sprintf( '%s[%s]', $parent, $panel ); $groups_id = sprintf( 'wpforms-conditional-groups-%s-%s', $parent, $panel ); $enabled = ! empty( $form_data[ $parent ][ $panel ]['conditional_logic'] ) ? true : false; $action_selected = ! empty( $form_data[ $parent ][ $panel ]['conditional_type'] ) ? $form_data[ $parent ][ $panel ]['conditional_type'] : ''; $conditionals = ! empty( $form_data[ $parent ][ $panel ]['conditionals'] ) ? $form_data[ $parent ][ $panel ]['conditionals'] : array( array( array() ) ); } } else { $field_name = sprintf( '%s', $panel ); $groups_id = sprintf( 'wpforms-conditional-groups-%s', $panel ); $enabled = ! empty( $form_data[ $panel ]['conditional_logic'] ) ? true : false; $action_selected = ! empty( $form_data[ $panel ]['conditional_type'] ) ? $form_data[ $panel ]['conditional_type'] : ''; $conditionals = ! empty( $form_data[ $panel ]['conditionals'] ) ? $form_data[ $panel ]['conditionals'] : array( array( array() ) ); } // Output Conditional Logic toggle checkbox panel setting. wpforms_panel_field( 'checkbox', $panel, 'conditional_logic', $args['form'], esc_html__( 'Enable conditional logic', 'wpforms-lite' ), array( 'tooltip' => '' . esc_html__( 'How to use Conditional Logic', 'wpforms-lite' ) . '', 'parent' => $parent, 'subsection' => $subsection, 'input_id' => 'wpforms-panel-field-' . implode( '-', array_filter( array( $parent, $panel, $subsection, 'conditional_logic', 'checkbox' ) ) ), 'input_class' => 'wpforms-panel-field-conditional_logic-checkbox', 'class' => 'wpforms-conditionals-enable-toggle', 'data' => array( 'name' => $field_name, 'actions' => $actions, 'action-desc' => esc_attr( $action_desc ), ), ) ); break; default: $enabled = false; $field_name = ''; $reference = ''; $action_selected = ''; $action_desc = ''; $groups_id = ''; $actions = array(); $conditionals = array(); } // Only display the block details if conditional logic is enabled. if ( $enabled ) : $data_attrs .= 'data-input-name="' . esc_attr( $field_name ) . '"'; $style = $enabled ? '' : 'display:none;'; // Groups wrap open markup. printf( '
| '; printf( ''; echo ' | '; // Rule operator - allows the user to // determine the comparison operator used // for processing. echo ''; printf( ''; echo ' | '; // Rule value - allows the user to // determine the value we are using for // comparison. echo ''; if ( isset( $rule['field'] ) ) { // For empty/not empty fields the field value input is not needed so we disable it. if ( ! empty( $rule['operator'] ) && in_array( $rule['operator'], array( 'e', '!e' ), true ) ) { $disabled = 'disabled'; $rule['value'] = ''; } else { $disabled = ''; } if ( isset( $form_fields[ $rule['field'] ]['type'] ) && in_array( $form_fields[ $rule['field'] ]['type'], array( 'text', 'textarea', 'email', 'url', 'number', 'hidden', 'rating', 'net_promoter_score' ), true ) ) { $type = in_array( $form_fields[ $rule['field'] ]['type'], array( 'rating', 'net_promoter_score' ), true ) ? 'number' : 'text'; printf( '', $type, $field_name, $group_id, $rule_id, esc_attr( $rule['value'] ), $disabled ); } else { printf( ''; } } else { echo ''; } // End if(). echo ' | '; // Rule actions. echo ''; echo ''; echo ''; echo ' | '; echo '