Home › Forums › Quform WordPress › Time – Required fields don't work
- This topic has 18 replies, 5 voices, and was last updated 6 years, 10 months ago by
Ally.
- AuthorPosts
- May 6, 2013 at 7:34 pm #4299
polanko
ParticipantHi,
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
May 7, 2013 at 9:30 am #4322Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 7, 2013 at 4:47 pm #4336polanko
ParticipantThanks ; )
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>
May 8, 2013 at 9:33 am #4347Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 8, 2013 at 4:35 pm #4354polanko
ParticipantThanks 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.May 9, 2013 at 11:48 am #4361Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 9, 2013 at 11:24 pm #4369polanko
ParticipantHi 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.
May 10, 2013 at 2:37 am #4370josef777
ParticipantThis 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
May 10, 2013 at 9:14 am #4377Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 10, 2013 at 4:59 pm #4384polanko
ParticipantGreat! 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_12Thank you so much!!
May 10, 2013 at 6:25 pm #4385polanko
ParticipantGot 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.May 11, 2013 at 12:45 am #4391josef777
ParticipantAlly Promised me it will be added in the next release just like the date field 🙂
May 12, 2013 at 10:42 am #4397Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
May 13, 2013 at 3:39 pm #4430polanko
ParticipantCool ; )
July 2, 2013 at 4:01 am #5079Harrison-Ort
ParticipantI 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.
- AuthorPosts
- You must be logged in to reply to this topic.