witajcie,
mam taki problem,
napisałem walidację formularza w PHP, wszystko działa poprawnie, tylko chciałbym aby po nieudanej walidacji zaznaczone radiobuttony i pola tekstowe zostawały w takim stanie jakim były przed wciśnięciem przycisku button, jednak jeżeli wcisne submita, i brakuje mi tylko jednego zaznaczenia w całym formularzu, skrypt wystawia powiadomienie o braku i zwraca formularz, ale wyczyszczony, chciałbym to zmienić. Gdzie jest błąd ? Lub co trzeba dopisać ?
Zdefiniowany formularz:
<form role="form" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="row">
<div class="form-group">
<ul>
<label><li> Strona Internetowa: </li></label>
<label> Jak ocenia Pani/Pan system nawigacji na stronie?</label><br>
<input id="1a" name="1" type="radio" value="1" /><label for="1a"> 1 </label>
<input id="2a" name="1" type="radio" value="2" /><label for="2a"> 2 </label>
<input id="3a" name="1" type="radio" value="3" /><label for="3a"> 3 </label>
<input id="4a" name="1" type="radio" value="4" /><label for="4a"> 4 </label>
<input id="5a" name="1" type="radio" value="5" /><label for="5a"> 5 </label>
<input type="text" name="uwagia" class="form-control" id="uwagia" placeholder="Tutaj można wpisać uwagi"><br>
<label> Jak ocenia Pani/Pan dostęp informacji na stronie?</label><br>
<input id="1b" name="2" type="radio" value="1" /><label for="1b"> 1 </label>
<input id="2b" name="2" type="radio" value="2"/><label for="2b"> 2 </label>
<input id="3b" name="2" type="radio" value="3"/><label for="3b"> 3 </label>
<input id="4b" name="2" type="radio" value="4"/><label for="4b"> 4 </label>
<input id="5b" name="2" type="radio" value="5"/><label for="5b"> 5 </label>
<input type="text" name="uwagib" class="form-control" id="uwagib" placeholder="Tutaj można wpisać uwagi"><br>
<label> Jak ogólnie ocenia Pani/Pan stronę internetową firmy?</label><br>
<input id="1c" name="3" type="radio" value="1" /><label for="1c" required> 1 </label>
<input id="2c" name="3" type="radio" value="2"/><label for="2c" required> 2 </label>
<input id="3c" name="3" type="radio" value="3"/><label for="3c" required> 3 </label>
<input id="4c" name="3" type="radio" value="4"/><label for="4c" required> 4 </label>
<input id="5c" name="3" type="radio" value="5"/><label for="5c" required> 5 </label>
<input type="text" name="uwagic" class="form-control" id="uwagic" placeholder="Tutaj można wpisać uwagi"><br>
</div>
<ul>
<div class="form-group">
<label><li> Obsługa klienta: </li></label>
<label> Jak ocenia Pani/Pan uprzejmość naszych konsultantów? </label><br>
<input id="1d" name="4" type="radio" value="1" /><label for="1d"> 1 </label>
<input id="2d" name="4" type="radio" value="2"/><label for="2d"> 2 </label>
<input id="3d" name="4" type="radio" value="3"/><label for="3d"> 3 </label>
<input id="4d" name="4" type="radio" value="4"/><label for="4d"> 4 </label>
<input id="5d" name="4" type="radio" value="5"/><label for="5d"> 5 </label>
<input type="text" name="uwagid" class="form-control" id="uwagid" placeholder="Tutaj można wpisać uwagi"><br>
<label> Jak ocenia Pani/Pan pomocność naszych konsultantów? </label><br>
<input id="1e" name="5" type="radio" value="1" /><label for="1e"> 1 </label>
<input id="2e" name="5" type="radio" value="2"/><label for="2e"> 2 </label>
<input id="3e" name="5" type="radio" value="3"/><label for="3e"> 3 </label>
<input id="4e" name="5" type="radio" value="4"/><label for="4e"> 4 </label>
<input id="5e" name="5" type="radio" value="5"/><label for="5e"> 5 </label>
<input type="text" name="uwagie" class="form-control" id="uwagie" placeholder="Tutaj można wpisać uwagi"><br>
<label> Jak ogólnie ocenia Pani/Pan obsługę klienta firmy?</label><br>
<input id="1f" name="6" type="radio" value="1" /><label for="1f"> 1 </label>
<input id="2f" name="6" type="radio" value="2"/><label for="2f"> 2 </label>
<input id="3f" name="6" type="radio" value="3"/><label for="3f"> 3 </label>
<input id="4f" name="6" type="radio" value="4"/><label for="4f"> 4 </label>
<input id="5f" name="6" type="radio" value="5"/><label for="5f"> 5 </label>
<input type="text" name="uwagif" class="form-control" id="uwagif" placeholder="Tutaj można wpisać uwagi"><br>
</div>
<div class="form-group">
<label><li> Serwis: </li></label><br>
<label> Jak ocenia Pani/Pan kontakt z naszymi serwisantami? </label><br>
<input id="1g" name="7" type="radio" value="1" /><label for="1g"> 1 </label>
<input id="2g" name="7" type="radio" value="2"/><label for="2g"> 2 </label>
<input id="3g" name="7" type="radio" value="3"/><label for="3g"> 3 </label>
<input id="4g" name="7" type="radio" value="4"/><label for="4g"> 4 </label>
<input id="5g" name="7" type="radio" value="5"/><label for="5g"> 5 </label>
<input type="text" name="uwagig" class="form-control" id="uwagig" placeholder="Tutaj można wpisać uwagi"><br>
<label> Jak ocenia Pani/Pan pomocność naszych konsultantów? </label><br>
<input id="1h" name="8" type="radio" value="1" /><label for="1h"> 1 </label>
<input id="2h" name="8" type="radio" value="2"/><label for="2h"> 2 </label>
<input id="3h" name="8" type="radio" value="3"/><label for="3h"> 3 </label>
<input id="4h" name="8" type="radio" value="4"/><label for="4h"> 4 </label>
<input id="5h" name="8" type="radio" value="5"/><label for="5h"> 5 </label>
<input type="text" name="uwagih" class="form-control" id="uwagih" placeholder="Tutaj można wpisać uwagi"><br>
<label> Jak ogólnie ocenia Pani/Pan obsługę klienta firmy?</label><br>
<input id="1i" name="9" type="radio" value="1" /><label for="1i"> 1 </label>
<input id="2i" name="9" type="radio" value="2"/><label for="2i"> 2 </label>
<input id="3i" name="9" type="radio" value="3"/><label for="3i"> 3 </label>
<input id="4i" name="9" type="radio" value="4"/><label for="4i"> 4 </label>
<input id="5i" name="9" type="radio" value="5"/><label for="5i"> 5 </label>
<input type="text" name="uwagii" class="form-control" id="uwagii" placeholder="Tutaj można wpisać uwagi"><br>
</div>
<div class="form-group">
<li><label for="message">Dodatkowe informacje</label>
<textarea name="uwagio" class="form-control" rows="6" id="uwagio" placeholder="W tym miejscu można zamieścić dodatkowe uwagi lub komentarze dotyczące naszego sprzętu, serwisu oraz strony" ></textarea>
</div>
</ul>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-default btn-lg btn-block btn-red" id="submit"><span class="glyphicon glyphicon-send"></span> Prześlij</button>
<input type="reset" class="btn btn-default btn-lg btn-block btn-red" value="Wyczyść formularz">
</div>
</div>
</form>
Skrypt walidujący:
<?php
header ("Content-Type: text/html; charset=utf-8");
if(isset($_POST['submit'])) {
if(trim($_POST['1']) == '') {
$hasError = true;
} else {
$jeden = trim($_POST['1']);
}
if(trim($_POST['2']) == '') {
$hasError = true;
} else {
$dwa = trim($_POST['2']);
}
if(trim($_POST['3']) == '') {
$hasError = true;
} else {
$trzy = trim($_POST['3']);
}
if(trim($_POST['4']) == '') {
$hasError = true;
} else {
$cztery = trim($_POST['4']);
}
if(trim($_POST['5']) == '') {
$hasError = true;
} else {
$piec = trim($_POST['5']);
}
if(trim($_POST['6']) == '') {
$hasError = true;
} else {
$szesc = trim($_POST['6']);
}
if(trim($_POST['7']) == '') {
$hasError = true;
} else {
$siedem = trim($_POST['7']);
}
if(trim($_POST['8']) == '') {
$hasError = true;
} else {
$osiem = trim($_POST['8']);
}
if(trim($_POST['9']) == '') {
$hasError = true;
} else {
$dziewiec = trim($_POST['9']);
}
if(trim($_POST['uwagia']) == '') {
$uwagiaa = 'Brak';
} else {
$uwagiaa =trim($_POST['uwagia']);
}
if(trim($_POST['uwagib']) == '') {
$uwagibb = 'Brak';
} else {
$uwagibb =trim($_POST['uwagib']);
}
if(trim($_POST['uwagic']) == '') {
$uwagicc = 'Brak';
} else {
$uwagicc =trim($_POST['uwagic']);
}
if(trim($_POST['uwagid']) == '') {
$uwagidd = 'Brak';
} else {
$uwagidd =trim($_POST['uwagid']);
}
if(trim($_POST['uwagie']) == '') {
$uwagiee = 'Brak';
} else {
$uwagiee =trim($_POST['uwagie']);
}
if(trim($_POST['uwagif']) == '') {
$uwagiff = 'Brak';
} else {
$uwagiff =trim($_POST['uwagif']);
}
if(trim($_POST['uwagig']) == '') {
$uwagigg = 'Brak';
} else {
$uwagigg =trim($_POST['uwagig']);
}
if(trim($_POST['uwagih']) == '') {
$uwagihh = 'Brak';
} else {
$uwagihh =trim($_POST['uwagih']);
}
if(trim($_POST['uwagii']) == '') {
$uwagiii = 'Brak';
} else {
$uwagiii =trim($_POST['uwagii']);
}
if(trim($_POST['uwagio']) == '') {
$uwagioo = 'Brak';
} else {
$uwagioo =trim($_POST['uwagio']);
}
}
?>