91 lines
3.0 KiB
Plaintext
91 lines
3.0 KiB
Plaintext
@using BLAIzor.Models
|
|
@using BLAIzor.Services
|
|
@using Microsoft.AspNetCore.Identity.UI.Services
|
|
@inject IEmailSender _emailService
|
|
|
|
|
|
<h1>Contact us!</h1>
|
|
@* <DynamicEditForm Data="@ContactFormModel" OnSubmit="OnSubmit" isEditing="true"></DynamicEditForm> *@
|
|
<EditForm Model="@ContactFormModel" OnValidSubmit="HandleValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
<ValidationSummary />
|
|
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Your Name</label>
|
|
<InputText id="name" class="form-control" @bind-Value="ContactFormModel.Name" placeholder="Enter your name" oninput="@ContentChanged" />
|
|
<ValidationMessage For="@(() => ContactFormModel.Name)" />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Your Email</label>
|
|
<InputText id="email" class="form-control" @bind-Value="ContactFormModel.Email" placeholder="Enter your email" oninput="@ContentChanged" />
|
|
<ValidationMessage For="@(() => ContactFormModel.Email)" />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="email" class="form-label">Subject (why are you contacting us)</label>
|
|
<InputText id="email" class="form-control" @bind-Value="ContactFormModel.Subject" placeholder="Subject" oninput="@ContentChanged" />
|
|
<ValidationMessage For="@(() => ContactFormModel.Subject)" />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="message" class="form-label">Your Message (minimum 10 words)</label>
|
|
<InputTextArea id="message" class="form-control mytextarea" @bind-Value="ContactFormModel.Message" placeholder="Enter your message" rows="5" oninput="@ContentChanged" />
|
|
<ValidationMessage For="@(() => ContactFormModel.Message)" />
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Submit</button>
|
|
</EditForm>
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter] public ContactFormModel ContactFormModel { get; set; }
|
|
private string? SuccessMessage;
|
|
private string? ErrorMessage;
|
|
|
|
[Parameter] public string? DocumentEmailAddress { get; set; } = "";
|
|
[Parameter] public EventCallback OnDataChanged { get; set; }
|
|
|
|
private async Task HandleValidSubmit()
|
|
{
|
|
try
|
|
{
|
|
|
|
// Simulate sending an email
|
|
await ((EmailService)_emailService).SendEmailAsync(ContactFormModel, DocumentEmailAddress);
|
|
SuccessMessage = "Thank you for contacting us! Your message has been sent.";
|
|
ErrorMessage = null;
|
|
|
|
// Clear the form
|
|
ContactFormModel = new();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ErrorMessage = "An error occurred while sending your message. Please try again later.";
|
|
SuccessMessage = null;
|
|
}
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
|
|
|
|
}
|
|
|
|
private void OnSubmit(object data)
|
|
{
|
|
|
|
}
|
|
|
|
async Task ContentChanged()
|
|
{
|
|
Console.Write("Data changed!!");
|
|
await OnDataChanged.InvokeAsync();
|
|
}
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
Console.WriteLine($"form initialized: {DocumentEmailAddress}");
|
|
}
|
|
} |