Set a hidden field value by a date

Home Forums Quform WordPress Set a hidden field value by a date

This topic is: resolved
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #26076
    sercofim
    Participant

    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!

    #26109
    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.

    #26120
    sercofim
    Participant

    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);

    #26156
    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.

Viewing 4 posts - 1 through 4 (of 4 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