Currently, I am working on developing a straightforward booking calendar using Eonasdan's bootstrap-datetimepicker, which relies on the moment.js
library. To incorporate localization, I have included the necessary file. My setup consists of linked pickers for input fields and a button that triggers an email to be sent with the selected dates via a simple AJAX request. However, upon form submission, I encountered the following error:
// locale-hr.js (line 89, col 1)
TypeError: this is undefined switch (this.day()) {
The excerpt from the specific lines causing the issue (88-102) is as follows:
nextWeek : function () {
switch (this.day()) {
case 0:
return '[u] [Sunday] [u] LT';
case 3:
return '[u] [Wednesday] [u] LT';
case 6:
return '[u] [Saturday] [u] LT';
case 1:
case 2:
case 4:
case 5:
return '[u] dddd [u] LT';
}
},
While the dates are successfully retrieved from the calendar, no emails are actually being sent out. Here is my Ajax script:
$(function() {
$("#reservationForm").on("submit", function(e) {
e.preventDefault();
var url = "../bin/reservation.php";
// storing dates from each picker
var date1 = $("#datetimepicker1").data("DateTimePicker").date();
var date2 = $("#datetimepicker2").data("DateTimePicker").date();
$.ajax({
type: "POST",
url: url,
data: { date1: date1, date2: date2 },
}).done(function(response) {
alert("Message sent");
});
});
});
And here is the corresponding PHP script:
<?php
if ( empty($_POST['date1']) || empty($_POST['date2']) ) {
echo ERROR_NO_ARGS;
return false;
}
$date1 = $_POST['date1'];
$date2 = $_POST['date2'];
$to = 'example@example.com';
$email_subject = "Title";
$email_body = "Selected dates:" . "From $date1 to $date2";
$headers = "From: Contact form\n";
$headers .= "Content-Type: text/plain; charset=utf-8" . "\r\n";
mail($to, $email_subject, $email_body, $headers);
return true;
?>
This seems like a mildly complex issue. If you have any suggestions or solutions regarding why the locale-hr.js file may be encountering issues referencing objects, please share. Additionally, if there are known fixes or improvements to consider, feel free to inform me. Your input is greatly appreciated. You can also view the code on jsfiddle, though it currently lacks the AJAX call due to initial unfamiliarity with the platform. I may revisit later to rectify this. Thank you in advance.