• Resolved Richard

    (@richardelovia)


    Hi,

    I’m creating a reservation form for some tours and when building the form, I set up a timepicker field.
    However, I wanted the field to open the default timepicker of the OS, especially on mobiles (iOS and Android).

    So instead of the provided timepicker field I inserted an HTML field and filled it with the string: <input type="time"/>

    When looking at the field preview in the visual editor of the HTML field the timepicker is being displayed correctly. But when looking at the pubblished form on the website page the timepicker is not showing at all.

    I inspected by browser the HTML field and it is empty, how can I solve this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Support Zafer – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @richardelovia

    I hope you are doing well today!

    Please share the link to a form page so that we can check further.

    Also it would be great if you can share an export of the form which will help us more.

    You can find more info on how to export the form here : https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export

    After exporting, please share the code using a service such as https://pastebin.com which is free to use.

    Please always make sure to use such service to share the code and don’t post the code here directly as it will most likely be unusable.

    Kind regards,
    Zafer

    Thread Starter Richard

    (@richardelovia)

    Hi,

    unfortunately I can not post the link of the page as it I’m working on a draft post in order to not show errors to the users.
    I’ve uploaded three screens on drive so you can see what I was talking about:

    1. I set the <input type="time"/> HTML field in the form:
    https://drive.google.com/file/d/1QhUV6TG79bgj7h0bauKOHRZtSgWx3ZMd/view?usp=sharing

    2. The HTML field preview correctly shows the timepicker in the visual editor:
    https://drive.google.com/file/d/1msj4ib9u7syFW-MTxQzC5ZaLh_nDsvbK/view?usp=sharing

    3. The timepicker is not being displayed in the form and the code of the HTML field is empty:
    https://drive.google.com/file/d/1fGPbY1GTXMSAYhVkrJLfw4KM3PJv_3MX/view?usp=sharing

    The form is a little bit messy beacuse I have to adjust some CSS but it is fine.

    I’ve created a pastebin with the form code exported. I’ve set a week time expiration. If it’s not going to be enough please let me know so I can share it again. Here’s the link:
    https://pastebin.com/rp28GcAu

    Best regards.

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @richardelovia

    Thank you for response and additional information!

    The way you tried to achieve this will not work and there are two reasons for that:

    – even though you are putting HTML code into HTML field, there’s only a limited set of HTML tags that can be used there and “input” is not one of them; this is related to security – field content is sanitized and some tags are stripped out of it to prevent possible XSS and similar “injection” attacks.

    – even if it would be allowed, Forminator wouldn’t really process such field and save it, it’s a bit more complex to handle fields.

    We’ll need to take slightly different approach then and just change the type of field “on the fly” before it’s rendered, server-side. Here’s how to do this:

    1. instead of using HTML field with HTML code in it, simply put a new field of “input” type on the form (edit form, click on “add field” and select “input” one);

    drag and drop the field where you want it to show;

    let’s say that the new input field that you added is {text1} field

    2. create empty file with a .php extension (e.g. “forminator-input-time-field.php”)

    3. copy this code and paste it into that file:

    <?php 
    
    add_filter( 'forminator_field_text_markup', 'wpmu_input_type_time', 10, 2 );
    function wpmu_input_type_time( $html, $field ) {
    	
    	if ( 'text-1' == $field['element_id'] ) {
    
    		$html = str_replace( 'type="text"', 'type="time"', $html );	
    
    	}
    
    	return $html;
    }

    4. in this line

    if ( 'text-1' == $field['element_id'] ) {

    adjust text-1 string to match your input field ID (but without curly brackets!)

    5. save the file and upload it to the “/wp-content/mu-plugins” folder of your WordPress installation

    That’s it. It will automatically change the type=text of the {text-1} input field to type=time and it will do this before the form markup is even sent to the browser so it should work with every browser/device that supports type=time input fields.

    Best regards,
    Adam

    Thread Starter Richard

    (@richardelovia)

    Hi @wpmudev-support8 thanks a lot that works like a charm.
    Thank you very much for being so helpful, y’all are amazing!

    Best regards,
    Have a great day!

    • This reply was modified 2 years, 4 months ago by Richard.
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Input type time not being displayed’ is closed to new replies.