Skip to content

Commit

Permalink
fix: issue OpenClassrooms-Student-Center#2 implement form entries
Browse files Browse the repository at this point in the history
  • Loading branch information
InesJT committed Sep 21, 2024
1 parent c42a188 commit 822ccf2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
11 changes: 6 additions & 5 deletions starterOnly/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ <h1 class="hero-headline">
>
<div
class="formData">
<label>Prénom</label><br>
<label for="first">Prénom</label><br>
<input
class="text-control"
type="text"
Expand All @@ -75,17 +75,18 @@ <h1 class="hero-headline">
</div>
<div
class="formData">
<label>Nom</label><br>
<label for="last">Nom</label><br>
<input
class="text-control"
type="text"
id="last"
name="last"
minlength="2"
/><br>
</div>
<div
class="formData">
<label>E-mail</label><br>
<label for="email">E-mail</label><br>
<input
class="text-control"
type="email"
Expand All @@ -95,7 +96,7 @@ <h1 class="hero-headline">
</div>
<div
class="formData">
<label>Date de naissance</label><br>
<label for="birthdate">Date de naissance</label><br>
<input
class="text-control"
type="date"
Expand All @@ -105,7 +106,7 @@ <h1 class="hero-headline">
</div>
<div
class="formData">
<label>À combien de tournois GameOn avez-vous déjà participé ?</label><br>
<label for="quantity">À combien de tournois GameOn avez-vous déjà participé ?</label><br>
<input type="number" class="text-control" id="quantity" name="quantity" min="0" max="99">
</div>
<p class="text-label">A quel tournoi souhaitez-vous participer cette année ?</p>
Expand Down
24 changes: 23 additions & 1 deletion starterOnly/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,26 @@ function closeModal() {
modalbg.style.display = "none";
}


function validate() {
// validate first name field
const firstValue = document.getElementById("first").value;
if (firstValue.length < 2) return false;
// validate last name field
const lastValue = document.getElementById("last").value;
if (lastValue.length < 2) return false;
// validate email field
const emailValue = document.getElementById("email").value;
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(emailValue)) return false;
// validate quantity field
const quantityValue = document.getElementById("quantity").value;
if (quantityValue.length === 0) return false;
// validate that at least one radio button for location is selected
const locationBtns = document.getElementsByName("location");
let locationSelected = false;
locationBtns.forEach((btn) => locationSelected = locationSelected || btn.checked);
if (!locationSelected) return false;
// validate that the general conditions are read and accepted
const generalConditions = document.getElementById("checkbox1");
if (!generalConditions.checked) return false;
return true;
}

0 comments on commit 822ccf2

Please sign in to comment.