Stwórz stronę z formularzem kontaktowym, który umożliwia:
kontakt.html<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Formularz kontaktowy</title>
</head>
<body>
<form id="formularz">
<label for="imie">Imię:</label>
<input type="text" id="imie" name="imie">
<label for="email">Email:</label>
<input type="email" id="email" name="email">
<label for="wiadomosc">Wiadomość:</label>
<textarea id="wiadomosc" name="wiadomosc"></textarea>
<button type="button" onclick="walidujFormularz()">Wyślij</button>
<div id="komunikat"></div>
</form>
<script>
function walidujFormularz() {
const imie = document.getElementById('imie').value.trim();
const email = document.getElementById('email').value.trim();
const wiadomosc = document.getElementById('wiadomosc').value.trim();
const komunikat = document.getElementById('komunikat');
if (!imie || !email || !wiadomosc) {
komunikat.style.color = 'red';
komunikat.textContent = 'Proszę wypełnić wszystkie pola!';
return;
}
if (!email.includes('@')) {
komunikat.style.color = 'red';
komunikat.textContent = 'Niepoprawny email!';
return;
}
komunikat.style.color = 'green';
komunikat.textContent = 'Formularz został poprawnie wypełniony!';
}
</script>
</body>
</html>