Is it possible to fill a field on a dependance former field?

Hi,
I’m looking for a way to have a field filled that depends on the content of a former field.
The reason why?
I’v to import a .csv file into a database, de “automated filled field” reflects an Id to a table in that database.
Without the filled field I have to translate manualy to an Id .

Suppose:
value given formfield, so by an user = “Car”
“Car” reflects Id number in the table as number 10.

So, I like to have a formfield with the Id number, based on given formfield.

(I hope I’m clear enough describing my wish).

Ron

add_filter( 'gform_pre_submission', 'populate_id_based_on_value' );

function populate_id_based_on_value( $form ) {
    // Map of values to IDs
    $value_id_map = array(
        'Car' => 10,
        // add other values and corresponding IDs
    );
    
    // Get the value from form field with ID 1
    $value = rgpost( 'input_1' );

    // Find the corresponding ID
    $id = $value_id_map[$value];
    
    // Set the ID in the form field with ID 2
    $_POST['input_2'] = $id;
}

Replace the ‘input_1’ and ‘input_2’ with your actual form field IDs. The $value_id_map array should be updated with the actual mappings from values to IDs.

I hope that helps. Let me know how that goes! :smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.