jQuery(document).ready(function($) {
    $(document).on('wpcf7mailsent', function(event) {
        // Extract form data from event.detail
        var formData = event.detail.inputs;
        var submittedValues = {};

        // Loop through the form data and extract values
        formData.forEach(function(input) {
            submittedValues[input.name] = input.value;
        });

        // Example: Use the submitted values for custom logic
        console.log('Form data:', submittedValues);

        // Redirect based on submitted data (for example, include a value in the URL)
        // Redirect based on submitted data (for example, include a value in the URL)
var redirectUrl = 'https://www.eastcoastfinancing.com/thank-you-vehicle/?other=1&phone='+ encodeURIComponent(submittedValues['contact-phone'])+'&email='+ encodeURIComponent(submittedValues['contact-email'])+'&first-name='+ encodeURIComponent(submittedValues['contact-fname'])+'&last-name='+ encodeURIComponent(submittedValues['contact-lname'])+'&postal-code='+ encodeURIComponent(submittedValues['contact-postal'])+'&city='+ encodeURIComponent(submittedValues['contact-city'])+'&address='+ encodeURIComponent(submittedValues['contact-address']) ; 

var redirectUrl = 'https://www.eastcoastfinancing.com/thank-you-vehicle/?other=1&phone=' + 
    encodeURIComponent(submittedValues['contact-phone']) + 
    '&email=' + encodeURIComponent(submittedValues['contact-email']) + 
    '&postal-code=' + encodeURIComponent(submittedValues['contact-postal']) + 
    '&city=' + encodeURIComponent(submittedValues['contact-city']) + 
    '&address=' + encodeURIComponent(submittedValues['contact-address']);

// Check for 'contact-fname' or 'contact-first'
if (submittedValues['contact-fname']) {
    var firstName = submittedValues['contact-fname'] ; 
    redirectUrl += '&first-name=' + encodeURIComponent(firstName);
}
else if(submittedValues['contact-first']){
  var firstName = submittedValues['contact-first'];
  redirectUrl += '&first-name=' + encodeURIComponent(firstName);
}

// Check for 'contact-lname' or 'contact-last'
if (submittedValues['contact-lname']) {
    var lastName = submittedValues['contact-lname'] || submittedValues['contact-last'];
    redirectUrl += '&last-name=' + encodeURIComponent(lastName);
}
else if(submittedValues['contact-last']){
var lastName = submittedValues['contact-last'];
redirectUrl += '&last-name=' + encodeURIComponent(lastName);
}
if (submittedValues['form_name']) {
    var form_name = submittedValues['form_name'] ;
    
    if(form_name!='')
    redirectUrl += '&form_name=' + encodeURIComponent(form_name);
    else
     redirectUrl += '&form_name=main_finance_app';
}
else{
 redirectUrl += '&form_name=main_finance_app';
}
console.log(redirectUrl);
        window.location.href = redirectUrl;
    });
});