Contactform saves input into db

This commit is contained in:
Francesco Lorenzo D'Amico
2026-08-18 16:44:42 +02:00
parent 7fb60d6f55
commit ee9e8de354
2 changed files with 56 additions and 3 deletions
+6 -3
View File
@@ -939,9 +939,12 @@
<div class="contact-form-box style-two">
<form action="https://formspree.io/f/myyleorq"
method="POST"
id="dreamit-form">
@if (Model.ContactFormSubmitted)
{
<div class="alert alert-success">Danke für deine Nachricht! Ich melde mich so schnell wie möglich.</div>
}
<form method="post" id="dreamit-form">
<h4>
Schreib mir eine Nachricht
+50
View File
@@ -1,12 +1,62 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesMovie.Data;
using RazorPagesMovie.Models;
namespace RazorPagesMovie.Pages
{
public class BewerbungModel : PageModel
{
private readonly RazorPagesMovieContext _context;
public BewerbungModel(RazorPagesMovieContext context)
{
_context = context;
}
[BindProperty]
public string Name { get; set; } = string.Empty;
[BindProperty]
public string Email { get; set; } = string.Empty;
[BindProperty]
public string? Phone { get; set; }
[BindProperty]
public string? Subject { get; set; }
[BindProperty]
public string Message { get; set; } = string.Empty;
public bool ContactFormSubmitted { get; set; }
public void OnGet()
{
}
public async Task<IActionResult> OnPostAsync()
{
var contactMessage = new ContactMessage
{
Name = Name,
Email = Email,
Phone = Phone,
Subject = Subject,
Message = Message
};
if (!TryValidateModel(contactMessage, nameof(ContactMessage)))
{
return Page();
}
_context.ContactMessage.Add(contactMessage);
await _context.SaveChangesAsync();
ContactFormSubmitted = true;
return Page();
}
}
}