How to change <input name="..."> to something else?

Hi - I am in dire need of connecting a form to a third party booking engine. But to pass the parameters I just need to rename 3 input fields to be specific names such as “arrival” “departure”…instead of the default gravity forms which is "input name=“input_1_7”.

An example field on my simple form is a date picker for the arrivals:

I can’t see a way to just rename/replace the input name alone so I am using some code supplied on the support website to change the entire input tag to the following:

add_filter( ‘gform_field_input’, ‘arrival’, 10, 5 );
function arrival( $input, $field, $value, $lead_id, $form_id ) {
// because this will fire for every form/field, only do it when it is the specific form and field
if ( $form_id == 1 && $field->id == 7 ) {
$input = ‘’;
}
return $input;
}

This works in as much as it replaces the entire input field (including the name) but the problem is that it stops the date picker from showing and messes up the formatting visually by removing the calendar icon and moving the position of the label.

Does anyone have any solutions?

Is there a better way to just rename the input name itsef?

Renaming the inputs like that won’t work. Take a look at the gform_after_submission hook:

Example 3 shows how to send data to a 3rd party site with your own parameter name.

Thanks for the reply Chris.

It doesn’t seem to work - though I am unsure if I am using the correct numbers for $entry.

Are these literally 1 for the first field, 2 for the second etc?

Also how would this be specific just to my 1 form? I am running multiple GFs.

You can inspect the source of the page where the form is shown to get the field IDs. They are not necessarily the order in which you added them to the form, or the order they are displayed in. Additionally, complex fields like address and name have multiple parts (for example, if the Name field was field 1 in the form, first name is $entry['1.3'] and last name is $entry['1.6']). If you have any question, add this logging line to your gform_after_submission function, to log the entry, so you can look up the proper field IDs:

GFCommon::log_debug( __METHOD__ . '(): My Entry => ' . print_r( $entry, true ) );

To apply gform_after_submission to just one form, you can call the hook like this:

// apply to form ID 7 only
add_action( 'gform_after_submission_7', 'send_to_api', 10, 2 );
function sent_to_api( $entry, $form ) {
    GFCommon::log_debug( __METHOD__ . '(): My Entry => ' . print_r( $entry, true ) );
    // now do something with all that information
}

Be sure logging is enabled while you are trying to set this us, otherwise that logging line is not going to do you any good.

© 2008 - 2019. Gravity Forms is a project by Rocketgenius Inc.