@@ -302,7 +302,16 @@ export class FeedbackForm {
302
302
}
303
303
@State ( ) editorContent : string = '' ;
304
304
@State ( ) responseMessage : string = '' ;
305
-
305
+ @State ( ) userName : string = '' ; // State to capture user's name
306
+ @State ( ) userEmail : string = '' ; // State to capture user's email
307
+ handleInputChange ( event : Event , field : 'name' | 'email' ) {
308
+ const input = event . target as HTMLInputElement ;
309
+ if ( field === 'name' ) {
310
+ this . userName = input . value ;
311
+ } else if ( field === 'email' ) {
312
+ this . userEmail = input . value ;
313
+ }
314
+ }
306
315
//Before performing any operations- GET or SET- ensure that the this.editor instance is available
307
316
//send email also without backend
308
317
async getContentFromEditor ( ) {
@@ -331,13 +340,21 @@ export class FeedbackForm {
331
340
this . responseMessage = 'Submission failed!' ;
332
341
}
333
342
343
+ // Ensure all required fields are filled
344
+ if ( ! this . userName || ! this . userEmail || ! this . editorContent ) {
345
+ alert ( 'Please fill out all fields before submitting.' ) ;
346
+ return ;
347
+ }
334
348
// Call EmailJS to send the email (Browser based or client based)
335
349
//Emailjs dashboard: https://dashboard.emailjs.com/sign-up
336
350
//templateParams is this.editorContent
351
+ //Template ID not found: https://dashboard.emailjs.com/admin/templates
337
352
emailjs . send (
338
353
'service_2q5gm3h' , // Email service ID from EmailJS dashboard
339
- 'template_rf0n5eq' , // Template ID from EmailJS dashboard
340
- { content : this . editorContent } , // Template parameters (the content of the email)
354
+ 'template_szeawas' , // Template ID from EmailJS dashboard
355
+ { user_name : this . userName ,
356
+ user_email : this . userEmail ,
357
+ content : this . editorContent } , // Template parameters (the content of the email)
341
358
{
342
359
publicKey : 'IRGsyXDXq7ZJHMbzF' ,
343
360
} // Your user ID from EmailJS: YOUR_PUBLIC_KEY
@@ -379,6 +396,23 @@ export class FeedbackForm {
379
396
return (
380
397
< div >
381
398
< h1 > Feedback Form</ h1 >
399
+ < label >
400
+ Name:
401
+ < input
402
+ type = "text"
403
+ placeholder = "Enter your name"
404
+ onInput = { ( event ) => this . handleInputChange ( event , 'name' ) }
405
+ required />
406
+ </ label >
407
+ < br />
408
+ < label >
409
+ Email:
410
+ < input
411
+ type = "email"
412
+ placeholder = "Enter your email"
413
+ onInput = { ( event ) => this . handleInputChange ( event , 'email' ) }
414
+ required />
415
+ </ label >
382
416
< div
383
417
id = { editorId }
384
418
ref = { ( el : HTMLElement ) => ( this . _targetRef = el ) }
0 commit comments