This topic is: resolved
- This topic has 3 replies, 2 voices, and was last updated 7 years, 1 month ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
Home › Forums › Quform WordPress › Set a hidden field value by a date
Hi,
I have to set a hidden field value calculating the age by an inserted date of birth. The calculation is not from ‘now’ but from a future date (the date of an event). I have to set two categories ‘under 14 years old’ and ‘over 40 years old’ in the date of a future event.
Is there a way to get this from a custom php code or in other ways?
Thank you!
You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
Hi Ally,
Thank you for your reply.
What about following php code?
add_filter(‘quform_post_validate_1’, function (array $result, Quform_Form $form) {
$date_birth = $form->getValue(‘quform_1_12’);
$age = date_diff(date_create($date_birth), date_create(‘2018-08-05’))->y;
if ($age >= 40) {
$form->setValue(‘quform_1_58’, ‘OVER40’);
} elseif ($age < 14) {
$form->setValue(‘quform_1_58’, ‘UNDER14’);
} else {
$form->setValue(‘quform_1_58′,’UNDER40’);
}
return $result;
}, 10, 2);
You don't have permission to view this content. Please log in or register and then verify your purchases to gain access.