Time – Required fields don't work

Home Forums Quform WordPress Time – Required fields don't work

This topic is: resolved
Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #4299
    polanko
    Participant

    Hi,

    Time fields are always completed, so the required field behavior doesn’t work.
    How could I solve that?
    Is there any way to add some hh, mm ?

    Thanks in advance

    #4322
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4336
    polanko
    Participant

    Thanks ; )

    Now, I can view the HH&MM in the drop-down list, but It’s not possible to set it like the default value (via Form builder UI).

    I tryed the following code but It didn’t work.

    <option value="" selected>MM</option>

    #4347
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4354
    polanko
    Participant

    Thanks again.

    Now, HH&MM values appear fixed in drop-down. That’s great.
    But some problem remains the same, Quform takes those values (HH&MM) and when you submit the form, It doesn’t require real time values.

    Please, take a look at the attached image.

    Attachments:
    You must be logged in to view attached files.
    #4361
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4369
    polanko
    Participant

    Hi Ally,

    The hour validation works fine, but the minute one does not work.

    In fact, you can set the time this way: “23:MM” and submit the form successfully.
    But when you don’t set the minutes (and leave MM), something sets them randomly and also breaks the hour previously set)

    So, the “23:MM” submitted could become “9:22” (?) in the email you received.

    Thanks.

    #4370
    josef777
    Participant

    This is a working code for your functions.php file .
    after you make the changes to time.php put the following in your theme functions.php


    add_action('iphorm_pre_display_1', 'mytheme_fix_time', 10, 1);

    function mytheme_fix_time($form)
    {
    // Sets the default time to HH:MM
    $time = $form->getElement('iphorm_1_11');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));

    }

    add_action('iphorm_element_valid_iphorm_1_11', 'mytheme_validate_time', 10, 3);

    function mytheme_validate_time($valid, $value, $element)
    {
    // Validates that the time is not empty
    if ($value['hour'] === '' || $value['minute'] === '') {
    $element->addError('This field is required');
    $valid = false;
    }
    return $valid;
    }

    I had this code from Ally back then and it works perfect . just don’t forget to change the form id and the field id to your ids

    #4377
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4384
    polanko
    Participant

    Great! Now time elements work exactly like I want. Thank you!!

    I have 2 time elements (start time and end time).
    So I have two “Time element unique ID”
    ¿How should I code that?


    function mytheme_fix_time($form)
    {
    // Sets the default time to HH:MM
    $time = $form->getElement('iphorm_1_11');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));

    }

    add_action('iphorm_element_valid_iphorm_1_11', 'mytheme_validate_time', 10, 3);

    Imagine both cases:
    $time = $form->getElement(‘iphorm_1_11’); >>>>> & iphorm_1_12
    add_action(‘iphorm_element_valid_iphorm_1_11’, ‘mytheme_validate_time’, 10, 3); >>>>> & iphorm_1_12

    Thank you so much!!

    #4385
    polanko
    Participant

    Got it!!

    I had an obvious php syntax problem that I solved this way:


    add_action('iphorm_pre_display_4', 'mytheme_fix_time', 10, 1);

    function mytheme_fix_time($form)
    {
    // Sets the default time to HH:MM
    $time = $form->getElement('iphorm_4_21');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));
    $time = $form->getElement('iphorm_4_22');
    $time->setValue(array('hour' => '', 'minute' => '', 'ampm' => 'am'));

    }

    add_action('iphorm_element_valid_iphorm_4_21', 'mytheme_validate_time', 10, 3);
    add_action('iphorm_element_valid_iphorm_4_22', 'mytheme_validate_time', 10, 3);

    I don’t know It’s the best way but It works.
    Thanks again for your awesome support.

    Attachments:
    You must be logged in to view attached files.
    #4391
    josef777
    Participant

    Ally Promised me it will be added in the next release just like the date field 🙂

    #4397
    Ally
    Support Staff

    You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.

    #4430
    polanko
    Participant

    Cool ; )

    #5079
    Harrison-Ort
    Participant

    I had the code mentioned above working, but then I accidentally deleted the form and after creating another one, replacing the ids, the default values (HH, MM) doesn’t work anymore. Now it’s showing 12:00 am and I would like to have it as (HH, MM). Why the function is not applying for this form? Again, I’ve replaced the ids. Before was 1_12 and now is 3_25. Any help is very much appreciated since I can’t launch the site just because of this issue.

    Thanks.

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy