Website Development Prices

Search Blog

Sunday, July 17, 2016

Prikazivanje svih podataka sa forme (Displaying all data from form)

Primer: slanje podataka u formi.

HTML kod


<!DOCTYPE html>
<html>
<head>
<title>Web forme i validacija unosa korisnika</title>
</head>



<body>

<h2>Slanje podataka u formi</h2>
<form action="prikazivanje-svih-podataka.php" method="post">
Kako se zovete? 
<input name="Ime" type="text">
<br /><br />
Izaberite vasa dva omiljena motora:
<select name="Motor[]" multiple>
<option>Suzuki</option>
<option>Honda</option>
<option>KTM</option>
<option>Yamaha</option>
<option>Ducati</option>
</select>
<br /><br />
<input type="submit" value="Posaljite">
</form>

</body>
</html>

Sacuvajte ovaj fajl kao slanje-podataka.html, u folderu htdocs, foldera xampp. U mom primeru, putanja je C:/xampp2/htdocs/PHPtuts/prikaz-svih-podataka/slanje-podataka.html.

Rezultat:




PHP kod

<!DOCTYPE html>
<html>
<head>
<title>Web forme i validacija unosa korisnika</title>
</head>

<body>
<h1>Prikazivanje svih podataka sa forme</h1>
Podaci iz forme:
<br /><br />

<?php
foreach ($_POST as $kljuc => $vrednost) {
if (is_array($vrednost)) {
foreach ($vrednost as $stavka) {
echo $kljuc, " => ", $stavka, "<br />";
}
}
else {
echo $kljuc, " => ", $vrednost, "<br />";
}
}
?>

</body>
</html>

Sacuvajte ovaj fajl kao prikazivanje-svih-podataka.php u istom folderu kao i slanje-podataka.html.

Rezultat:




Example: sending data in the form.

HTML code

<!DOCTYPE html>
<html>
<head>
<title>Web forms and validation of user input</title>

</head>
<body>

<h2>Sending data in form</h2>
<form action="displaying-all-data.php" method="post">
What is your name? 
<input name="Name" type="text">
<br /><br />
Choose your two favorite motorcycles:
<select name="Motorcycle[]" multiple>
<option>Suzuki</option>
<option>Honda</option>
<option>KTM</option>
<option>Yamaha</option>
<option>Ducati</option>
</select>
<br /><br />
<input type="submit" value="Send">
</form>

</body>

</html>

Save this file as a sending-data.html, in the htdocs folder, of the folder xampp. In my example, the path is C:/xampp2/htdocs/PHPtuts/display-of-all-data/sending-data.html.

Result:



PHP code

<!DOCTYPE html>
<html>
<head>
<title>Web forms and validation of user input</title>
</head>

<body>
<h1>Displaying all data from form</h1>
Data from form:
<br /><br />

<?php
        foreach ($_POST as $key => $value) {
            if (is_array($value)) {
                foreach ($value as $item) {
                    echo $key, " => ", $item, "<br />";
                }
            }
            else {
                echo $key, " => ", $value, "<br />";
            }
        }
    ?>

</body>

</html>

Save this file as displaying-all-data.php in the same folder as the sending-data.html.


Result:



No comments:

Post a Comment

Note: Only a member of this blog may post a comment.