Browse Source

success message for action forms

am
farhan 4 months ago
parent
commit
9782552d21

+ 3
- 6
app/Http/Controllers/MainController.php View File

19
             return view('rsvp-digital-card');
19
             return view('rsvp-digital-card');
20
         } else {
20
         } else {
21
             return view('digital-card', compact(['rsvp', 'guestbook']));
21
             return view('digital-card', compact(['rsvp', 'guestbook']));
22
+            // return view('rsvp-digital-card');
22
         }
23
         }
23
     }
24
     }
24
 
25
 
31
 
32
 
32
         session()->flash('success', 'Terima kasih kerana sudi menghadirkan diri!');
33
         session()->flash('success', 'Terima kasih kerana sudi menghadirkan diri!');
33
 
34
 
34
-        return response()->json(['message' => 'RSVP form submitted successfully']);
35
+        return response()->json(['message' => 'Terima kasih kerana sudi menghadirkan diri!']);
35
     }
36
     }
36
 
37
 
37
     public function saveSpeech(Request $request) {
38
     public function saveSpeech(Request $request) {
42
 
43
 
43
         session()->flash('success', 'Terima kasih atas ucapan anda!');
44
         session()->flash('success', 'Terima kasih atas ucapan anda!');
44
 
45
 
45
-        return response()->json(['message' => 'Speech form submitted successfully']);
46
-    }
47
-
48
-    public function rsvpmain() {
49
-        return view('rsvp-digital-card');
46
+        return response()->json(['message' => 'Terima kasih atas ucapan anda!']);
50
     }
47
     }
51
 }
48
 }

+ 3
- 0
resources/views/digital-card.blade.php View File

46
         </style>
46
         </style>
47
     </head>
47
     </head>
48
     <body class="antialiased font-serif no-scroll">
48
     <body class="antialiased font-serif no-scroll">
49
+        <div role="alert" class="alert alert-success hidden z-40 fixed w-1/2 top-3 right-3">
50
+            <span></span>
51
+        </div>
49
         <div class="petal-overlay" id="petalOverlay">
52
         <div class="petal-overlay" id="petalOverlay">
50
             <img src="{{ asset('assets/petal.gif') }}" alt="Falling Petals">
53
             <img src="{{ asset('assets/petal.gif') }}" alt="Falling Petals">
51
         </div>
54
         </div>

+ 6
- 3
resources/views/modals/guestbook-modal.blade.php View File

42
             data: formData,
42
             data: formData,
43
             success: function(response) {
43
             success: function(response) {
44
               $('#closeSpeechForm').submit();
44
               $('#closeSpeechForm').submit();
45
-              if ('{{ session('success') }}') {
46
-                  showSuccessMessage('{{ session('success') }}');
47
-              }
45
+              var alertContainer = $('.alert-success');
46
+              alertContainer.find('span').text(response.message); // Set message text
47
+              alertContainer.fadeIn().removeClass('hidden'); // Show the alert
48
+              setTimeout(function() {
49
+                  alertContainer.fadeOut().addClass('hidden'); // Hide the alert after 5 seconds
50
+              }, 3000);
48
             },
51
             },
49
             error: function(xhr, status, error) {
52
             error: function(xhr, status, error) {
50
               console.error('Error submitting form:', error);
53
               console.error('Error submitting form:', error);

+ 6
- 3
resources/views/modals/rsvp-modal.blade.php View File

48
           data: formData,
48
           data: formData,
49
           success: function(response) {
49
           success: function(response) {
50
             $('#closeRsvpForm').submit();
50
             $('#closeRsvpForm').submit();
51
-            if ('{{ session('success') }}') {
52
-                showSuccessMessage('{{ session('success') }}');
53
-            }
51
+            var alertContainer = $('.alert-success');
52
+            alertContainer.find('span').text(response.message); // Set message text
53
+            alertContainer.fadeIn().removeClass('hidden'); // Show the alert
54
+            setTimeout(function() {
55
+                alertContainer.fadeOut().addClass('hidden'); // Hide the alert after 5 seconds
56
+            }, 3000);
54
           },
57
           },
55
           error: function(xhr, status, error) {
58
           error: function(xhr, status, error) {
56
             console.error('Error submitting form:', error);
59
             console.error('Error submitting form:', error);

+ 9
- 20
resources/views/rsvp-digital-card.blade.php View File

15
     @vite(['resources/css/app.css'])
15
     @vite(['resources/css/app.css'])
16
 </head>
16
 </head>
17
 <body class="antialiased font-serif">
17
 <body class="antialiased font-serif">
18
+    <div role="alert" class="alert alert-success hidden z-40 fixed w-1/2 top-3 right-3">
19
+        <span></span>
20
+    </div>
18
     <audio id="player" autoplay="autoplay" loop>
21
     <audio id="player" autoplay="autoplay" loop>
19
         <source src="{{asset('assets/background-musicv2.mp3')}}" type="audio/mp3">
22
         <source src="{{asset('assets/background-musicv2.mp3')}}" type="audio/mp3">
20
     </audio>
23
     </audio>
77
               type: 'POST',
80
               type: 'POST',
78
               data: formData,
81
               data: formData,
79
               success: function(response) {
82
               success: function(response) {
80
-                if ('{{ session('success') }}') {
81
-                    showSuccessMessage('{{ session('success') }}');
82
-                }
83
                 $('#RSVPForm')[0].reset();
83
                 $('#RSVPForm')[0].reset();
84
+                var alertContainer = $('.alert-success');
85
+                alertContainer.find('span').text(response.message); // Set message text
86
+                alertContainer.fadeIn().removeClass('hidden'); // Show the alert
87
+                setTimeout(function() {
88
+                    alertContainer.fadeOut().addClass('hidden'); // Hide the alert after 5 seconds
89
+                }, 3000);
84
               },
90
               },
85
               error: function(xhr, status, error) {
91
               error: function(xhr, status, error) {
86
                 console.error('Error submitting form:', error);
92
                 console.error('Error submitting form:', error);
87
               }
93
               }
88
             });
94
             });
89
           });
95
           });
90
-    
91
-          function showSuccessMessage(message) {
92
-                // Create a dynamic success message element
93
-                var successAlert = $('<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative" role="alert">' +
94
-                    '<span class="block sm:inline">' + message + '</span>' +
95
-                    '</div>');
96
-    
97
-                // Append the message to a suitable container in your HTML (e.g., modal, form, or body)
98
-                $('#alert-success').append(successAlert);
99
-    
100
-                // Automatically remove the message after 3 seconds
101
-                setTimeout(function() {
102
-                    successAlert.fadeOut('slow', function() {
103
-                        $(this).remove();
104
-                    });
105
-                }, 3000); // 3 seconds
106
-            }
107
         });
96
         });
108
     </script>
97
     </script>
109
 </body>
98
 </body>

+ 1
- 4
routes/web.php View File

16
 
16
 
17
 Route::get('/', [MainController::class, 'main']);
17
 Route::get('/', [MainController::class, 'main']);
18
 Route::post('/saveRsvp', [MainController::class, 'saveRsvp'])->name('rsvp.save');
18
 Route::post('/saveRsvp', [MainController::class, 'saveRsvp'])->name('rsvp.save');
19
-Route::post('/saveSpeech', [MainController::class, 'saveSpeech'])->name('speech.save');
20
-
21
-
22
-Route::get('/rsvp', [MainController::class, 'rsvpmain']);
19
+Route::post('/saveSpeech', [MainController::class, 'saveSpeech'])->name('speech.save');

Loading…
Cancel
Save