Ajout du formulaire
This commit is contained in:
parent
fbbb3bf83c
commit
166db82ed3
@ -15,10 +15,28 @@ namespace GrossesMitaines.Controllers {
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index() {
|
||||
return View();
|
||||
}
|
||||
|
||||
// POST : LogIn
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Demande(RequestViewModel model, string returnurl)
|
||||
{
|
||||
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return LocalRedirect(returnurl);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
|
||||
return LocalRedirect(returnurl);
|
||||
}
|
||||
}
|
||||
|
||||
public IActionResult Privacy() {
|
||||
return View();
|
||||
}
|
||||
@ -31,12 +49,6 @@ namespace GrossesMitaines.Controllers {
|
||||
return View();
|
||||
}
|
||||
|
||||
public class ContactModel { }; // À DELETER QUAND LA CLASSE/FORMULAIRE SERONT FAIT.
|
||||
[HttpPost]
|
||||
public IActionResult ContactUs(ContactModel model) {
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error() {
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
|
@ -5,13 +5,8 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="ViewModels\**" />
|
||||
<Content Remove="ViewModels\**" />
|
||||
<EmbeddedResource Remove="ViewModels\**" />
|
||||
<None Remove="ViewModels\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentValidation" Version="11.2.2" />
|
||||
<PackageReference Include="FluentValidation.AspNetCore" Version="11.2.2" />
|
||||
<PackageReference Include="FontAwesome" Version="4.7.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.17" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.17" />
|
||||
|
35
GrossesMitaines/GrossesMitaines/Models/RequestViewModel.cs
Normal file
35
GrossesMitaines/GrossesMitaines/Models/RequestViewModel.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using FluentValidation;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace GrossesMitaines.Models
|
||||
{
|
||||
public class RequestViewModel
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string Phone { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
|
||||
public class RequestValidator : AbstractValidator<RequestViewModel>
|
||||
{
|
||||
public RequestValidator()
|
||||
{
|
||||
RuleFor(x => x.Name)
|
||||
.NotEmpty().WithMessage("Vous devez entrer votre nom")
|
||||
.MinimumLength(2).WithMessage("Votre nom doit être de 2 lettres minimum");
|
||||
|
||||
RuleFor(x => x.Email)
|
||||
.NotEmpty().WithMessage("Un Email est requis")
|
||||
.Matches("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$").WithMessage("Format non valide!");
|
||||
|
||||
RuleFor(x => x.Phone)
|
||||
.NotEmpty().WithMessage("Vous devez entrer votre téléphone")
|
||||
.Matches("^[0-9][0-9][0-9]-[0-9][0-9][0-9]-[0-9][0-9][0-9][0-9]$").WithMessage("Téléphone non valide!");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
using FluentValidation.AspNetCore;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.HttpsPolicy;
|
||||
@ -19,6 +20,8 @@ namespace GrossesMitaines {
|
||||
|
||||
public void ConfigureServices(IServiceCollection services) {
|
||||
services.AddControllersWithViews();
|
||||
|
||||
services.AddFluentValidation(option => option.RegisterValidatorsFromAssemblyContaining<Startup>());
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
|
||||
|
@ -1,4 +1,6 @@
|
||||
@{
|
||||
@model GrossesMitaines.Models.RequestViewModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Maison";
|
||||
}
|
||||
|
||||
@ -19,3 +21,50 @@
|
||||
<br>
|
||||
<br>
|
||||
<vc:en-vedette></vc:en-vedette>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12 bg-info">
|
||||
<section>
|
||||
<form asp-controller="Home" asp-action="Demande" asp-route-returnurl="/Home/Index" method="post" class="form-horizontal" role="form">
|
||||
<h4 class="text-center text-white">Demander une renconte!</h4>
|
||||
<div class="form-group">
|
||||
<div class="col-md-12">
|
||||
<label class="text-white">Nom*</label>
|
||||
<input asp-for="Name" class="form-control" value="NOM COMPLET" />
|
||||
<span asp-validation-for="Name" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-12">
|
||||
<label class="text-white">Email*</label>
|
||||
<input asp-for="Email" class="form-control" value="COURRIEL" />
|
||||
<span asp-validation-for="Email" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-12">
|
||||
<label class="text-white">Téléphone*</label>
|
||||
<input asp-for="Phone" class="form-control" value="TÉLÉPHONE EX: 450-111-1111" />
|
||||
<span asp-validation-for="Phone" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-12">
|
||||
<label class="text-white">Message</label>
|
||||
<input asp-for="Message" class="form-control" value="VOS COMMENTAIRES" rows="3"/>
|
||||
<span asp-validation-for="Message" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="col-md-offset-2 col-md-12">
|
||||
<button type="submit" class="btn btn-default bg-success">Demande</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
@{ await Html.RenderPartialAsync("_ValidationScriptsPartial"); }
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user