• Resolved norbou

    (@norbou)


    Hi Franky,

    I noticed that after submitting the registration form, the values for the number of updates and available seats are not updated. We had a problem with this last year because when multiple people start filling out the form at the same time, it depends on who is faster. The slower ones keep signing up for groups that are already full, but they still see vacancies on their form, which is very confusing.
    Does the Events Made Easy plugin provide an API? I would need to update the #_AVAILABLESEATS field using ajax.

    I can add something like:

    
    // Load data when page loads
    updateSeats();
    
    // Update the data every minute (60000 milliseconds)
    setInterval(updateSeats, 60000);
    
    // Load the data when the form is submitted
    document.getElementById('eme-rsvp-form').addEventListener('submit', function(e) {
    e.preventDefault(); // Stop submitting the form until we get the data
    updateSeats(function() {
    document.getElementById('eme-rsvp-form').submit(); // Submit the form after the data is retrieved
    });
    });
    
    function updateSeats(callback) {
    $.ajax({
    url: '/path/to/your/server/api',
    method: 'GET',
    dataType: 'json',
    success: function(data) {
    for (var i = 1; i <= 53; i++) {
    var seatElement = document.querySelector("#_AVAILABLESEATS{" + i + "}");
    if (seatElement) {
    seatElement.innerText = data[i.toString()];
    }
    }
    if (callback) {
    callback();
    }
    }
    });
    }
    
    

    Unfortunately, I don’t know what to specify as the server API path.

    Thank You!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter norbou

    (@norbou)

    Something like this would do the job?

    add_action('rest_api_init', function () {
    register_rest_route('eme/v1', '/available-seats/', array(
    'methods' => 'GET',
    'callback' => 'eme_get_available_seats',
    ));
    });
    
    function eme_get_available_seats(WP_REST_Request $request) {
    // Kód pro získání po?tu dostupnych sedadel
    // Nahra?te tento kód konkrétním zp?sobem, jak získat dostupná sedadla na základě va?í aplikace
    $available_seats = array();
    for ($i = 1; $i <= 53; $i++) {
    $available_seats[$i] = get_option("_AVAILABLESEATS{" . $i . "}", 0);
    }
    
    return new WP_REST_Response($available_seats, 200);
    }

    Plugin Author Franky

    (@liedekef)

    Please use github for all EME support questions (and make sure to update to the latest version released there first, we’re at 2.3.69). See https://www.e-dynamics.be/wordpress/forums/topic/security-release/ and https://github.com/liedekef/events-made-easy/

    Thread Starter norbou

    (@norbou)

    Thank you, I have it done.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘#_AVAILABLESEATS Ajax update’ is closed to new replies.