Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • MaartenVissers 32 posts 150 karma points
    Feb 10, 2022 @ 08:44
    MaartenVissers
    0

    Umbraco - Unobtrusive Validation

    I kwow that this may not be directly related to Umbraco, but I can't seem to get my Unobtrusive validation to work. Do I have to configure something else? Something in the Startup.cs?

    I've added these scripts:

    <script src="~/js/jquery-3.5.1.min.js"></script>
    <script src="~/js/jquery-migrate-3.0.0.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.3/jquery.validate.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ajax-unobtrusive/3.2.6/jquery.unobtrusive-ajax.min.js"></script>
    

    This is my model:

    public class ContactFormModel
        {
            public const string TempDataKey = "ContactSuccess";
    
            public string PlaceHolderName { get; } = string.Empty;
            public string PlaceHolderEmail { get; } = string.Empty;
            public string PlaceHolderSubject { get; } = string.Empty;
            public string PlaceHolderMessage { get; } = string.Empty;
            public string ButtonText { get; } = string.Empty;
            public string SuccesMessage { get; } = string.Empty;
            public string ErrorMessage { get; } = string.Empty;
    
            [Required]
            public string Name { get; set; }
    
            [Required]
            [EmailAddress]
            public string Email { get; set; }
    
            [Required]
            [MaxLength(500)]
            public string Message { get; set; }
    
            public ContactFormModel()
            {
            }
    
            public ContactFormModel(Home home)
            {
                PlaceHolderName = home.ContactFormNameLabel;
                PlaceHolderEmail = home.ContactFormEmailLabel;
                PlaceHolderMessage = home.ContactFormMessageLabel;
                ButtonText = home.ContactFormButtonText;
                SuccesMessage = "Uw mail is verzonden";
                ErrorMessage = "Er is iets misgegaan bij het verzenden van uw mail";
            }
        }
    

    And this is my form:

    @using(Html.BeginUmbracoForm<HomeController>(nameof(HomeController.SendMail), FormMethod.Post))
    {
        <div class="col-md-12">
            <input type="text" asp-for="Name" id="name" placeholder="@Model.PlaceHolderName">
        </div>
        <div class="col-md-12">
            <input type="email" asp-for="Email" id="email" placeholder="@Model.PlaceHolderEmail">
        </div>
        <div class="col-md-12">
            <textarea asp-for="Message" id="message" cols="40" rows="3" placeholder="@Model.PlaceHolderMessage"></textarea>
        </div>
        <div class="col-md-12">
            <button class="butn-dark mt-15" type="submit"><a href="#0"><span>@Model.ButtonText</span></a></button>
        </div>
    }
    
  • Greg Fyans 140 posts 342 karma points
    Feb 10, 2022 @ 15:51
    Greg Fyans
    0

    What does the rendered form look like, are you seeing your data-val-* attributes?

  • MaartenVissers 32 posts 150 karma points
    Feb 10, 2022 @ 19:08
    MaartenVissers
    0

    Hi Greg, thanks for your reply. I do see the data-val-* attributes.

Please Sign in or register to post replies

Write your reply to:

Draft