0

I am trying to extend GF_Field in Gravity Forms.

In this use case I require 2 input fields. The fields do get set with the correct values, but when it posts/next page, the values are not saving within GF.

I've reviewed this similar question: Custom Gravity Forms Field with Multiple Inputs

I've used their code as a baseline, but mine wont save/update the values. Any GF experts have insight?

I've also tried rgpost(), and using _1 in rgget(). GF's documentation on this is very lacking.

/**
 * Define the fields inner markup.
 *
 * @param array $form The Form Object currently being processed.
 * @param string|array $value The field value. From default/dynamic population, $_POST, or a resumed incomplete submission.
 * @param null|array $entry Null or the Entry Object currently being edited.
 *
 * @return string
 */
public function get_field_input( $form, $value = '', $entry = null ) {
    $form_id  = $form['id'];
    $field_id = intval( $this->id );
    $is_entry_detail = $this->is_entry_detail();
    $is_form_editor  = $this->is_form_editor();

    $ng_timestamp = $ng_friendly = '';
    if ( is_array( $value ) ) {
        $ng_timestamp = esc_attr( rgget( 'input_' . $this->id . '_1', $value ));
        $ng_friendly  = esc_attr( rgget( 'input_' . $this->id . '_2', $value ));
       
    }
    //$value = esc_attr( $value );

    // Get the value of the inputClass property for the current field.
    // Duplicate this line for additional params
    $inputNg = $this->inputNg;
    $inputNgName = $this->inputNgName;
    $inputNgDuration = $this->inputNgDuration;
    $inputNgDetails = $this->inputNgDetails;

    // Prepare the input classes.
    $size         = $this->size;
    $class_suffix = $is_entry_detail ? '_admin' : '';
    $class        = $size . $class_suffix . ' ';

    // Prepare the other input attributes.
    $tabindex              = $this->get_tabindex();
    $logic_event           = ! $is_form_editor && ! $is_entry_detail ? $this->get_conditional_logic_event( 'keyup' ) : '';
    $placeholder_attribute = $this->get_field_placeholder_attribute();
    $required_attribute    = $this->isRequired ? 'aria-required="true"' : '';
    $invalid_attribute     = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
    $disabled_text         = $is_form_editor ? 'disabled="disabled"' : '';

    $input = "<input name='input_{$field_id}.1' id='input_{$field_id}_{$form_id}_1'  type='hidden' value='{$ng_timestamp}' class='gf_apt_slot {$class}' {$tabindex} {$logic_event} {$placeholder_attribute} {$required_attribute} {$invalid_attribute} {$disabled_text}/>
                <input  name='input_{$field_id}.2' id='input_{$field_id}_{$form_id}_2' class='gf_apt_slot_friendly' value='{$ng_friendly}' type='hidden'/>";

    return sprintf( "<div class='ginput_container ginput_container_%s'>%s</div>", $this->type, $input );
}

public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
    if ( is_array( $value ) ) {
        $ng_timestamp = trim( rgget( 'input_' . $this->id . '.1', $value ) );
        $ng_friendly  = trim( rgget( 'input_' . $this->id . '.2', $value ) );
       

        $return = $ng_timestamp;
        $return .= ! empty( $return ) && ! empty( $ng_friendly ) ? " $ng_friendly" : $ng_friendly;

    } else {
        $return = '';
    }

    if ( $format === 'html' ) {
        $return = esc_html( $return );
    }

    return $return;
}
DDulla
  • 659
  • 9
  • 20

0 Answers0