Reply To: Limiting the number of entries – two date in one form

Home Forums Quform WordPress Limiting the number of entries – two date in one form Reply To: Limiting the number of entries – two date in one form

#36440
janheu
Participant

Hi, I´m coming back to this post since I have a similar idea.
We have multiple Dates set in a option field. Based on a selection made before,

First the user selects a place via dropdown -> afterwards he/she can select a date (option) based on that selection.

add_action('quform_pre_display_33', function (Quform_Form $form) {
global $wpdb;
$query = "SELECT COUNT(*)
FROM {$wpdb->prefix}quform_entry_data ed
LEFT JOIN {$wpdb->prefix}quform_entries e
ON ed.entry_id = e.id
WHERE e.form_id = %d AND ed.element_id = %d AND ed.value = %s";

// Erstes Radio-Button-Element
$uniqueId1 = '33_32';
$limits1 = array(
'03.02.2024' => 6,
'24.02.2024' => 6,
);
updateRadioOptions($form, $uniqueId1, $limits1, $wpdb, $query);

// Zweites Radio-Button-Element
$uniqueId2 = '33_33';
$limits2 = array(
'09.02.2024' => 6,
'17.02.2024' => 6,
);
updateRadioOptions($form, $uniqueId2, $limits2, $wpdb, $query);
});

function updateRadioOptions($form, $uniqueId, $limits, $wpdb, $query) {
$radio = $form->getElement('quform_' . $uniqueId);
if ($radio instanceof Quform_Element_Radio) {
$options = array();
foreach ($radio->getOptions() as $option) {
$value = isset($option['value']) ? $option['value'] : null;
if ($value && array_key_exists($value, $limits)) {
$count = $wpdb->get_var($wpdb->prepare($query, $form->getId(), $radio->getId(), $value));
if ($count < $limits[$value]) {
$options[] = $option;
}
} else {
$options[] = $option;
}
}
$radio->setOptions($options);
}
}

Thats the idea, somehow it doesnt seem to work, any idea how we can adjust it?
Is there a way to display a message if all spots for this place are already booked?
thanks a lot

Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy