[solved] Changing Field Labels in Gravity Forms with gform_pre_render

August 7, 2015

I have taken on a wordpress project recently which required me to change the language of the text in the field labels on some gravity forms.

The site is in one language, but within wordpress they have the option to show certain pages in a different language, for example Norwegian.

So, if we have a form with the default text of Name and Telephone and the form was being shown on a Norwegian page, then the text would need to display: Navn and Telefon.

On the left is the form with the english texts and on the right is the form when the setting of the page is set to Norwegian.

gform_pre_render

The guys at Gravity Help showed me this page: https://www.gravityhelp.com/documentation/article/gform_pre_render/ which is slightly too advanced for what I wanted to do because all I need to do is change the words in the gfield_label within the form.

In the end, I came up with this solution below which works perfectly:

add_filter( 'gform_pre_render', 'change_language_text_in_form_labels' );
function change_language_text_in_form_labels( $form ) {
	
	//get the language texts from landing page
	global $lp_first_name,$lp_email,$lp_phone;
	
	//swap out the text for the form fields
	//for the side form
	if ( $form['id'] == 3 ) {
		
		$form['fields'][1]->label = $lp_first_name;
		$form['fields'][2]->label = $lp_email;
		$form['fields'][3]->label = $lp_phone;
       
    }
	
	//swap out the text for the form fields
	//for the modal form
	if ( $form['id'] == 5 ) {
		
		$form['fields'][1]->label = $lp_first_name;
		$form['fields'][2]->label = $lp_email;
		$form['fields'][3]->label = $lp_phone;
       
    }
	
	return $form;
	
}