This repository has been archived by the owner on Jan 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ajout exemple de control de formulaire en js
- Loading branch information
Showing
1 changed file
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,44 @@ | ||
|
||
<form action="index.php?page=film-creation" method="post"> | ||
<form id="film-form" action="index.php?page=film-creation" method="post"> | ||
<fieldset> | ||
<legend>Nouveau film</legend> | ||
<label for="titre">titre :</label> | ||
<input type="text" name="titre" placeholder="titre du film"/> | ||
<input type="text" name="titre" placeholder="titre du film" required/> | ||
<label for="titre">auteur :</label> | ||
<input type="text" name="auteur" placeholder="auteur"/> | ||
<input type="text" name="auteur" placeholder="auteur" required/> | ||
<label for="titre">acteurs :</label> | ||
<input type="text" name="acteurs" placeholder="acteurs"/> | ||
<label for="titre">date de sortie :</label> | ||
<input type="text" name="date_sortie" placeholder="date de sortie"/> | ||
<input type="text" name="acteurs" placeholder="acteurs required"/> | ||
<label for="titre">année de sortie :</label> | ||
<input name="date_sortie" placeholder="date de sortie" required/> | ||
<input type="submit" name="ok" value="ok"/> | ||
<input type="reset" name="reset" value="effacer"/> | ||
</fieldset> | ||
</form> | ||
<script> | ||
//exemple de control sur un formulaire en js | ||
$btnSubmit = document.forms["film-form"]['ok']; | ||
$btnSubmit.onclick = function(e){ | ||
var valid = true; | ||
//test sur la date | ||
var dt_now=new Date(); | ||
var annee_sortie = parseInt(document.forms["film-form"]['date_sortie'].value); | ||
if (isNaN(annee_sortie) || annee_sortie < 1935 || annee_sortie > dt_now.getFullYear()){ | ||
valid = false; | ||
alert('oulala ça marche pas du tout pour la date...'); | ||
} | ||
if (!valid){ | ||
//on empêche le submit du formulaire | ||
e.preventDefault(); | ||
} | ||
} | ||
</script> | ||