
FullCalendar with Event Modal Dialog Example
In this example, We will learn how to FullCalendar with Event Modal Dialog Example. This example we will use jQuery, jQuery UI, FullCalendar, and Moment.js.
FullCalendar is useful for appointment booking, event scheduling, task management, and see which peoples are leave in this current month, etc.
You can select one date or multiple dates in this example and JSON type of data pass to events to display the calendar. you can add events for a particular date or update the event.
So you can see our example source code.
index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | <!DOCTYPE html> <html lang="en"> <head> <title>FullCalendar with Event Modal Dialog Example - XpertPhp</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.10.0/fullcalendar.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.2/moment.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.1.1/fullcalendar.min.js"></script> <script> $(document).ready(function() { $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, defaultDate: new Date(), defaultView: 'month', editable: true, events:'data.php', selectable:true, selectHelper:true, select: function(start, end, allDay) { var start = moment(start).format('YYYY-MM-DD HH:mm:ss'); var end = moment(end).format('YYYY-MM-DD HH:mm:ss'); sessionStorage.setItem('start_date', start); sessionStorage.setItem('end_date', end); $("#btnModal").trigger("click"); }, }); $("#btnBook").click(function(){ var txtTitle = $("#txtTitle").val(); if(txtTitle) { $.ajax({ url:"insert_data.php", type:"POST", data:{title:txtTitle,start:sessionStorage.getItem('start_date'),end:sessionStorage.getItem('end_date')}, success:function(data) { //alert(data); if(data == "success") { sessionStorage.setItem('start_date', ""); sessionStorage.setItem('end_date', ""); window.location.reload(); } } }) } }); }); </script> </head> <body> <div class="container"> <div id='calendar'></div> <button style="display: none" type="button" id="btnModal" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Add Book</h4> </div> <div class="modal-body"> <form> <div class="form-group"> <label for="txtTitle">Title:</label> <input type="text" name="txtTitle" class="form-control" id="txtTitle"> </div> <button type="button" id="btnBook" class="btn btn-default">Book</button> </form> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> </div> </div> </div> </div> </div> </body> </html> |
data.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <?php $hostname="localhost"; $username=""; $password=""; $dbname=""; // Create connection $conn = mysqli_connect($hostname, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "select * from booking ORDER BY id asc"; $result = mysqli_query($conn, $sql); $book_array = array(); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)){ $book_array[] = array( 'id' => $row["id"], 'title' => $row["title"], 'start' => $row["start"], 'end' => $row["end"] ); } } echo json_encode($book_array); ?> |
insert_data.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <?php $hostname="localhost"; $username=""; $password=""; $dbname=""; // Create connection $conn = mysqli_connect($hostname, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql = "INSERT INTO booking (title, start, end) VALUES('".$_POST['title']."','".$_POST['start']."','".$_POST['end']."')"; if (mysqli_query($conn, $sql)) { echo "success"; } else { echo "error"; } mysqli_close($conn); ?> |
If you like this article then You can see, comment and share this article demo
Please follow and like us: