cześć
Mialbym prośbe, a konkretniej mam problem z walidacją w swojej ankiecie/formularzu
w poniższym kodzie na samym poczatku zrobilem jakąś walidację(ale taką na "piechotę")
może ktoś z was mogłby mi pomóc przerobić w inny sposób tą walidację
jeszcze nie wiem jak zrobić walidację z checkboxami, tak żeby użytkownik wprowadził tylko 3 odpowiedzi nie mniej.
czekam na odpowiedź
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Ankieta na temat czasu wolnego i zainteresowań</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
</head>
<body id="main_body" >
<img id="top" src="top.png" alt="">
<div id="form_container">
<?php
if ($_POST['wyslij'])
{
$blad=false;
if ( isset($_POST['plec']) && (!empty($_POST['wiek'])) && isset($_POST['rozmiar']) && (!empty($_POST['wojewodztwo']))
&& isset($_POST['czas']) && isset($_POST['organizator']) && isset($_POST['miejsce']) && (!empty($_POST['zadanie_11']))
&& (!empty($_POST['zadanie_12'])) && isset($_POST['lacze']) && isset($_POST['cel']) )
{
echo "<h2>Dziękuję za udział w ankiecie</h1>";
}
else
{
echo "Odpowiedz na wszystkie pytania w ankiecie";
}
}
else{
?>
<h1><a>Ankieta dla młodzieży dotycząca czasu wolnego i zainteresowań.</a></h1>
<form method="post" action="index.php">
<div class="form_description">
<h2><p align="center">Ankieta dla młodzieży dotycząca czasu wolnego i zainteresowań.</p></h2>
</div></br>
<ul >
<li id="li_1">
<span><legend>1. Twoja płeć</legend></br>
<table><tr>
<td><label>Kobieta</label></td>
<td><input type="radio" class="element radio" name="plec" value="k" ></td>
</tr>
<tr>
<tr>
<td><label>Mężczyzna</label></td>
<td><input type="radio" class="element radio" name="plec" value="m" ></td>
</tr>
<tr>
</table>
</span>
<li id="li_2">
<span><legend>2. Podaj swój wiek</legend></br>
<table>
<input name="wiek" size="3" type="text" maxlength="2" value=""/>
</table>
</span>
<li id="li_3">
<span><legend>3. Twoje miejsce zamieszkania(aktualne)</legend></br>
<table><tr>
<td><label>wieś</label></td>
<td><input type="radio" class="element radio" name="rozmiar" value="wies" ></td>
</tr>
<tr>
<tr>
<td><label>miasto</label></td>
<td><input type="radio" class="element radio" name="rozmiar" value="miasto" ></td>
</tr>
<tr>
</table>
</span>
<li id="li_4">
<span>
<legend>4. Wybierz swoje województwo.</legend></br>
<table>
<select name="wojewodztwo">
<option value="">-- wybierz --</option>
<option value"" name="woj[]">dolnośląskie</option>
<option value"" name="woj[]">kujawsko-pomorskie</option>
<option value"" name="woj[]">lubelskie</option>
<option value"" name="woj[]">lubuskie</option>
<option value"" name="woj[]">łódzkie</option>
<option value"" name="woj[]">małopolskie</option>
<option value"" name="woj[]">mazowieckie</option>
<option value"" name="woj[]">opolskie</option>
<option value"" name="woj[]">podkarpackie</option>
<option value"" name="woj[]">podlaskie</option>
<option value"" name="woj[]">pomorskie</option>
<option value"" name="woj[]">śląskie</option>
<option value"" name="woj[]">świętokrzyskie</option>
<option value"" name="woj[]">warmińsko-mazurskie</option>
<option value"" name="woj[]">wielkopolskie</option>
<option value"" name="woj[]">zachodniopomorskie</option>
</select>
</table>
</span>
<li id="li_5" >
<span><legend>5. Jaką ilością czasu wolnego dysponujesz dziennie?</legend>
<table>
<tr>
<td><label>do 1 godziny</label></td>
<td><input type="radio" class="element radio" name="czas" value="do-1"></td>
</tr>
<tr>
<td><label>od 2 do 4 godzin</label></td>
<td><input type="radio" class="element radio" name="czas" value="2-4"></td>
</tr>
<tr>
<td><label>od 4 do 6 godzin</label></td>
<td><input type="radio" class="element radio" name="czas" value="4-6"></td>
</tr>
<tr>
<td><label>powyżej 6 godzin</label></td>
<td><input type="radio" class="element radio" name="czas" value=">6"></td>
</tr>
<tr>
<td><label>non stop przed komputerem</label></td>
<td><input type="radio" class="element radio" name="czas" value="nonstop"></td>
</tr>
</table>
</span>
</li>
<li id="li_6" >
<span>
<legend>6. Kto jest organizatorem zajęć pozalekcyjnych w Twojej miejscowości?</legend>
<table>
<tr>
<td><label>Dom kultury</label></td>
<td><input type="radio" class="element radio" name="organizator" value="dom kultury"></td>
</tr>
<tr>
<td><label>Szkoła</label></td>
<td><input type="radio" class="element radio" name="organizator" value="szkola"></td>
</tr>
<tr>
<td><label>Kościół</label></td>
<td><input type="radio" class="element radio" name="organizator" value="kosciol"></td>
</tr>
</table>
<label>inne instytucje, osoby(jakie?)</label>
<input name="inne2" type="text" maxlength="255" value=""/>
</span>
</li>
<li id="li_7" >
<span>
<legend>7. Gdzie najczęściej spędasz czas wolny?</legend>
<table>
<tr>
<td><label>dyskoteka</label></td>
<td><input type="radio" class="element radio" name="miejsce" value="dysko"></td>
</tr>
<tr>
<td><label>park</label></td>
<td><input type="radio" class="element radio" name="miejsce" value="park"></td>
</tr>
<tr>
<td><label>dom kultury</label></td>
<td><input type="radio" class="element radio" name="miejsce" value="dom-kultury"></td>
</tr>
<tr>
<td><label>boisko sportowe</label></td>
<td><input type="radio" class="element radio" name="miejsce" value="boisko"></td>
</tr>
<tr>
<td><label>u koleżanki/kolegi</label></td>
<td><input type="radio" class="element radio" name="miejsce" value="kol"></td>
</tr>
<tr>
<td><label>w domu</label></td>
<td><input type="radio" class="element radio" name="miejsce" value="dom"></td>
</tr>
<tr>
<td><label>pub</label></td>
<td><input type="radio" class="element radio" name="miejsce" value="pub"></td>
</tr>
</table>
<label>inne(wymień)</label>
<input name="inne" type="text" maxlength="255" value=""/>
</span>
</li>
<li id="li_8" >
<span>
<legend>8. Zaznacz urządzenia, które masz w domu.(możesz wybrać kilka odpowiedzi)</legend>
<table>
<tr>
<td><label>komputer/laptop</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="laptop"></td>
</tr>
<tr>
<td><label>komputer z dostępem do Internetu</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="komputerdI"></td>
</tr>
<tr>
<td><label>konsola do gier(typu Kinect, PlayStation)</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="konsola"></td>
</tr>
<tr>
<td><label>drukarka</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="drukarka"></td>
</tr>
<tr>
<td><label>telefon komórkowy</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="komorka"></td>
</tr>
<tr>
<td><label>Odtwarzacz DVD</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="dvd"></td>
</tr>
<tr>
<td><label>Kamera</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="kamera"></td>
</tr>
<tr>
<td><label>Aparat cyfrowy/Lustrzanka</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="aparat"></td>
</tr>
<tr>
<td><label>posiadam wszystkie wymienione</label></td>
<td><input type="checkbox" class="element checkbox" name="urzadzenie[]" value="pww"></td>
</tr>
</table>
<li id="li_9" >
<span>
<legend>9. W jaki sposób łączysz się z Internetem?</legend>
<table>
<tr>
<td><label>modem podłączony do linii telefonicznej (typu Neostrada)</label></td>
<td><input type="radio" class="element radio" name="lacze" value="modem"></td>
</tr>
<tr>
<td><label>telewizja kablowa</label></td>
<td><input type="radio" class="element radio" name="lacze" value="kablowka"></td>
</tr>
<tr>
<td><label>łącze radiowe</label></td>
<td><input type="radio" class="element radio" name="lacze" value="radiowo"></td>
</tr>
<tr>
<td><label>łączność mobilna</label></td>
<td><input type="radio" class="element radio" name="lacze" value="mobilnie"></td>
</tr>
<tr>
</table>
<label>inne...</label>
<input name="inne" type="text" maxlength="255" value=""/>
</span>
</li> </tr>
<li id="li_10" >
<span>
<legend>10. W jakim celu korzystasz z telefonu komórkowego?</legend>
<table>
<tr>
<td><label>kontakt ze znajomymi</label></td>
<td><input type="radio" class="element radio" name="cel" value="znajomi"></td>
</tr>
<tr>
<td><label>kontakt z rodzicami</label></td>
<td><input type="radio" class="element radio" name="cel" value="rodzice"></td>
</tr>
<tr>
<td><label>udział w konkursach/teleturniejach</label></td>
<td><input type="radio" class="element radio" name="cel" value="konkursy"></td>
</tr>
<tr>
<td><label>do celów rozrywkowych: robienia zdjęć, gra w gry, itp.</label></td>
<td><input type="radio" class="element radio" name="cel" value="rozrywka"></td>
</tr>
<tr>
</table>
<label>inne...</label>
<input name="inne" type="text" maxlength="255" value=""/>
</span>
</li></tr></br>
<li id="li_11" >
<label class="description" for="zadanie_11">11. W jakie dni tygodnia najwięcej czasu spędzasz przed komputerem i dlaczego.</br> Wymień i uzasadnij swoją odpowiedź. </label>
<div>
<textarea name="zadanie_11" type="text" maxlength="1024" value="" cols="50" rows="5"></textarea>
<!--<input id="element_3" name="element_3" class="element text large" type="text" maxlength="1024" value="" /> -->
</div>
</li></br>
<li id="li_12" >
<label class="description" for="zadanie_12">12. Co lubisz robić najbardziej, gdy masz wolne dni od nauki czy pracy ?. </label>
<div>
<textarea name="zadanie_12" type="text" maxlength="1024" value="" cols="50" rows="5"></textarea>
<!--<input id="element_3" name="element_3" class="element text large" type="text" maxlength="1024" value="" /> -->
</div>
</li></br>
<li class="buttons">
<input type="hidden" name="form_id" value="525402" />
<input id="saveForm" class="button_text" type="submit" name="wyslij" value="Wyślij do nas informacje" />
<input type="reset" value="Zresetuj wszystkie informacje"/>
</li>
</ul>
</form>
<?php
}
?>
</div>
<img id="bottom" src="bottom.png" alt="">
</body>
</html>