I have a register form and I have 3 inputs. They are working well when I post the values to the controller but when I don't fill them in and click the submit button, it's not allowing me to submit this form. When it's not allowing me to submit it, it should give me warning about those input like 'This field is required' or etc. but its not giving me that error.
The form:
<div class="form-container">
<div class="form-form">
<div class="form-form-wrap">
<div class="form-container">
<div class="form-content">
<h1 class="">Get started with a <br /> free account</h1>
<p class="signup-link">Already have an account? <a href="auth_login.html">Log in</a></p>
<form class="text-left" asp-action="Register" method="post">
<div class="form">
<div id="username-field" class="field-wrapper input">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
<input asp-for="User.UserName" type="text" class="form-control" placeholder="Username" required>
<span asp-validation-for="User.UserName" class="text-danger"></span>
</div>
<div id="email-field" class="field-wrapper input">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-at-sign"><circle cx="12" cy="12" r="4"></circle><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"></path></svg>
<input asp-for="User.UserEMail" type="text" value="" placeholder="Email" required>
<span asp-validation-for="User.UserEMail" class="text-danger"></span>
</div>
<div id="password-field" class="field-wrapper input mb-2">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-lock"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
<input asp-for="User.UserPassword" type="password" value="" placeholder="Password" required>
<span asp-validation-for="User.UserPassword" class="text-danger"></span>
</div>
<div class="field-wrapper terms_condition">
<div class="n-chk new-checkbox checkbox-outline-primary">
<label class="new-control new-checkbox checkbox-outline-primary">
<input type="checkbox" class="new-control-input">
<span class="new-control-indicator"></span><span>I agree to the <a href="javascript:void(0);"> terms and conditions </a></span>
</label>
</div>
</div>
<div class="d-sm-flex justify-content-between">
<div class="field-wrapper toggle-pass">
<p class="d-inline-block">Show Password</p>
<label class="switch s-primary">
<input type="checkbox" id="toggle-password" class="d-none">
<span class="slider round"></span>
</label>
</div>
<div class="field-wrapper">
<button type="submit" name="Register" class="btn btn-primary">Get Started!</button>
</div>
</div>
</div>
</form>
<p class="terms-conditions">© 2020 All Rights Reserved. <a href="index.html">CORK</a> is a product of Designreset. <a href="javascript:void(0);">Cookie Preferences</a>, <a href="javascript:void(0);">Privacy</a>, and <a href="javascript:void(0);">Terms</a>.</p>
</div>
</div>
</div>
</div>
<div class="form-image">
<div class="l-image">
</div>
</div>
</div>
I think there is something which overrides those warnings and not letting them to become visible but I just could not find it. When I remove the <span asp-validation-for="****" class="text-danger"></span>
it's still the same. I don't know which place I'm wrong and I hope someone can help me.
CodePudding user response:
Add the required attribute to the input fields.
The Boolean
required
attribute, if present, indicates that the user must specify a value for the input before the owning form can be submitted.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="form-container">
<div class="form-form">
<div class="form-form-wrap">
<div class="form-container">
<div class="form-content">
<h1 class="">Get started with a <br /> free account</h1>
<p class="signup-link">Already have an account? <a href="auth_login.html">Log in</a></p>
<form class="text-left" asp-action="Register" method="post">
<div class="form">
<div id="username-field" class="field-wrapper input">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-user"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>
<input asp-for="User.UserName" type="text" class="form-control" placeholder="Username" required>
<span asp-validation-for="User.UserName" class="text-danger"></span>
</div>
<div id="email-field" class="field-wrapper input">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-at-sign"><circle cx="12" cy="12" r="4"></circle><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"></path></svg>
<input asp-for="User.UserEMail" type="text" value="" placeholder="Email" required>
<span asp-validation-for="User.UserEMail" class="text-danger"></span>
</div>
<div id="password-field" class="field-wrapper input mb-2">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-lock"><rect x="3" y="11" width="18" height="11" rx="2" ry="2"></rect><path d="M7 11V7a5 5 0 0 1 10 0v4"></path></svg>
<input asp-for="User.UserPassword" type="password" value="" placeholder="Password" required>
<span asp-validation-for="User.UserPassword" class="text-danger"></span>
</div>
<div class="field-wrapper terms_condition">
<div class="n-chk new-checkbox checkbox-outline-primary">
<label class="new-control new-checkbox checkbox-outline-primary">
<input type="checkbox" class="new-control-input">
<span class="new-control-indicator"></span><span>I agree to the <a href="javascript:void(0);"> terms and conditions </a></span>
</label>
</div>
</div>
<div class="d-sm-flex justify-content-between">
<div class="field-wrapper toggle-pass">
<p class="d-inline-block">Show Password</p>
<label class="switch s-primary">
<input type="checkbox" id="toggle-password" class="d-none">
<span class="slider round"></span>
</label>
</div>
<div class="field-wrapper">
<button type="submit" name="Register" class="btn btn-primary">Get Started!</button>
</div>
</div>
</div>
</form>
<p class="terms-conditions">© 2020 All Rights Reserved. <a href="index.html">CORK</a> is a product of Designreset. <a href="javascript:void(0);">Cookie Preferences</a>, <a href="javascript:void(0);">Privacy</a>, and <a href="javascript:void(0);">Terms</a>.</p>
</div>
</div>
</div>
</div>
<div class="form-image">
<div class="l-image">
</div>
</div>
</div>
</body>
</html>