Replacing the input with a custom one [RESOLVED]

Dear, I’m using as the base line of code: https://docs.gravityforms.com/gform_field_input/#highlighter_445276.
I am creating a php and adding in function.php to change some information that is important of the input. The big question is, I need to make the change from type = “text” to type = “email” to all fields of the form that is email. Do you have any way to automatically identify all email input?
In my code below, my function is configured to look for the form and the specific field, which generates a bit of work and problems if a field is changed.

    add_filter( 'gform_field_input', 'tracker', 10, 5 );
function tracker( $input, $field, $value, $lead_id, $form_id ) {
    if ( $form_id == 1 && $field->id == 2 ) {
		$input = '<input name="input_2" id="input_1_2" type="email" value="" class="large" aria-required="true" aria-invalid="false">';
		return $input;
	}
	if ( $form_id == 2 && $field->id == 3 ) {
		$input = '<input name="input_3" id="input_2_3" type="email" value="" class="large" aria-required="true" aria-invalid="false">';
		return $input;
	}
}

is it possible to automatically configure for the function to modify all forms created in the email field type = “text” for type = “email” without having to specify the form id and field id?

Are you trying to make the change on the fly, for any text field, to change it to an email field? Are there any other text fields in the form that could inadvertently be affected by this code if it were to apply to all forms.

Also, can you explain why you’re trying to do this? What is the use-case?

In fact, only form fields that are properly e-mail. The input of these fields generates a type text. I need to make this change because one of the company’s system is responsible for capturing the registration of the data in these forms and the field of the email must be with type = “email”, if type = “text” does not work.

Be sure you have “Output HTML5” set to Yes on the Forms > Settings page. That will make the Email fields have the type=“email”. Will that work for you?

1 Like

Thanks a lot for the help, activating HTML5 really solved the problem.

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