Submit
jQuery(document).ready(function($) {
$('#guest_count').on('input', function() {
var value = parseInt($(this).val(), 10);
if (!isNaN(value) && value < 1) {
$(this).val('');
}
});
$('#private-event-form').submit(function(event) {
event.preventDefault(); // Prevent default form submission
var guestCount = parseInt($('#guest_count').val(), 10);
if (isNaN(guestCount) || guestCount < 1) {
$('#event-form-message').html('Please enter a valid number of guests (minimum 1).');
return;
}
// Define form data structure
var formData = {
lead: {
first_name: $('#first_name').val(),
last_name: $('#last_name').val(),
company: $('#company').val(),
phone_number: $('#phone_number').val(),
email_address: $('#email_address').val(),
event_date: $('#event_date').val(),
start_time: $('#start_time').val(),
guest_count: guestCount,
event_description: $('#event_description').val(),
additional_information: $('#additional_information').val(),
email_opt_in: $('#email_opt_in').is(':checked') ? 1 : 0,
gdpr_consent_granted: 1
},
lead_form_id: $('#lead_form_id').val()
};
// URL of the CRM endpoint
var crmEndpoint = 'https://api.tripleseat.com/v1/leads/create.js?public_key=bb69d8980de28fbc639ffa71aef1c88f1bc11615';
//var crmEndpoint = 'https://api.tripleseat.com/v1/leads/create.js?lead_form_id=38540&public_key=bb69d8980de28fbc639ffa71aef1c88f1bc11615';
// Make JSON request
$.ajax(crmEndpoint,
{data: formData,
dataType: 'JSONP',
crossDomain: true,
success: function(response) {
if (response.errors) {
// Handle errors
//$('#event-form-message').html('Error: ' + JSON.stringify(response.errors));
$('#event-form-message').html('Something wrong occured. Please retry later or contact us via email.');
$('#private-event-form').hide(); // Hide the form
} else {
// Handle success
//$('#event-form-message').html('Success: ' + JSON.stringify(response));
$('#event-form-message').html('Thank you for your interest in Freehand LA! We\'ve recorded your request and we will get back to you.');
$('#private-event-form').hide(); // Hide the form
}
},
error: function(jqXHR, textStatus, errorThrown) {
// Handle error
$('#event-form-message').html('GeneralError: ' + textStatus + ' - ' + errorThrown);
}
});
});
});