PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

forms don't validate after changing input type

  1. I read an interesting article over at CSS Tricks about making the form fields more suitable for smartphone / tablet input.

    To do so, I changed the input type of my email and phone fields as well as a single text field I am using for time with the gform_field_input filter (http://www.gravityhelp.com/documentation/page/Gform_field_input).

    This works perfect right up until the moment of submitting, then exactly for those fields I have changed the input type for don't validate anymore.

    Is there anything I'm missing here?

    The code I used is:

    /**
     * Add functionality to change input type Gravity Forms to optimize for tablets and smartphones
     * see article: http://css-tricks.com/a-couple-of-best-practices-for-tablet-friendly-design/
     * see GF help: http://www.gravityhelp.com/documentation/page/Gform_field_input
     */
    
    add_filter( 'gform_field_input', 'cf_gf_input_types', 10, 5 );
    function cf_gf_input_types( $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
    	// 4 forms all email fields
    	if ( $form_id == 1 && $field['id'] == 3 || $form_id == 3 && $field['id'] == 2 || $form_id == 4 && $field['id'] == 3 || $form_id == 5 && $field['id'] == 2 )
    	{
    		$input = '<input type="email">';
    	}
    
    	// 4 forms all phone fields; 2 forms time field
    	if (
    		$form_id == 1 && $field['id'] == 4 || $form_id == 3 && $field['id'] == 3 || $form_id == 4 && $field['id'] == 4 || $form_id == 5 && $field['id'] == 3
    		||
    		$form_id == 1 && $field['id'] == 15 || $form_id == 4 && $field['id'] == 15   )
    	{
    		$input = '<input type="number">';
    	}
    
    	return $input;
    }
    Posted 11 years ago on Monday June 24, 2013 | Permalink
  2. Richard Vav
    Administrator

    Rather than using that function I would go to the Gravity Forms general settings page and set 'Output HTML5' to 'Yes', which will automatically set the email, website and phone input types to the corresponding email, url or tel which mobile devices recognise and display the correct keyboard for.

    Posted 11 years ago on Monday June 24, 2013 | Permalink
  3. Hi Richard, thanks for your reply.
    Guess I learned something new today :) I honestly didn't know that.
    I turned it on and that indeed works perfect, except not on the time fields.

    Posted 11 years ago on Monday June 24, 2013 | Permalink
  4. Richard Vav
    Administrator

    Yep the HTML5 date and time types are still pending support by the browser developers
    http://docs.webplatform.org/wiki/html/elements/input/type/date
    http://docs.webplatform.org/wiki/html/elements/input/type/time

    Posted 11 years ago on Monday June 24, 2013 | Permalink

This topic has been resolved and has been closed to new replies.