Преглед изворни кода

success message for action forms

am
farhan пре 4 месеци
родитељ
комит
9782552d21

+ 3
- 6
app/Http/Controllers/MainController.php Прегледај датотеку

@@ -19,6 +19,7 @@ class MainController extends Controller
19 19
             return view('rsvp-digital-card');
20 20
         } else {
21 21
             return view('digital-card', compact(['rsvp', 'guestbook']));
22
+            // return view('rsvp-digital-card');
22 23
         }
23 24
     }
24 25
 
@@ -31,7 +32,7 @@ class MainController extends Controller
31 32
 
32 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 38
     public function saveSpeech(Request $request) {
@@ -42,10 +43,6 @@ class MainController extends Controller
42 43
 
43 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 Прегледај датотеку

@@ -46,6 +46,9 @@
46 46
         </style>
47 47
     </head>
48 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 52
         <div class="petal-overlay" id="petalOverlay">
50 53
             <img src="{{ asset('assets/petal.gif') }}" alt="Falling Petals">
51 54
         </div>

+ 6
- 3
resources/views/modals/guestbook-modal.blade.php Прегледај датотеку

@@ -42,9 +42,12 @@
42 42
             data: formData,
43 43
             success: function(response) {
44 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 52
             error: function(xhr, status, error) {
50 53
               console.error('Error submitting form:', error);

+ 6
- 3
resources/views/modals/rsvp-modal.blade.php Прегледај датотеку

@@ -48,9 +48,12 @@
48 48
           data: formData,
49 49
           success: function(response) {
50 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 58
           error: function(xhr, status, error) {
56 59
             console.error('Error submitting form:', error);

+ 9
- 20
resources/views/rsvp-digital-card.blade.php Прегледај датотеку

@@ -15,6 +15,9 @@
15 15
     @vite(['resources/css/app.css'])
16 16
 </head>
17 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 21
     <audio id="player" autoplay="autoplay" loop>
19 22
         <source src="{{asset('assets/background-musicv2.mp3')}}" type="audio/mp3">
20 23
     </audio>
@@ -77,33 +80,19 @@
77 80
               type: 'POST',
78 81
               data: formData,
79 82
               success: function(response) {
80
-                if ('{{ session('success') }}') {
81
-                    showSuccessMessage('{{ session('success') }}');
82
-                }
83 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 91
               error: function(xhr, status, error) {
86 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 97
     </script>
109 98
 </body>

+ 1
- 4
routes/web.php Прегледај датотеку

@@ -16,7 +16,4 @@ use App\Http\Controllers\MainController;
16 16
 
17 17
 Route::get('/', [MainController::class, 'main']);
18 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…
Откажи
Сачувај