Ako na Vasoj web stranici napravite tri razlicite HTML forme, svaka od njih treba da ima svoje dugme Submit. Kada korisnik izabere neko od ovih dugmadi, podaci iz forme se salju do PHP skripta:
<form name="forma1" action="php-dugmad-2.php" method="post">
<input type="submit" value="Dugme 1">
</form>
Da biste podatke poslali nazad do PHP skripta, dodacete u svaku formu po jednu skrivenu kontrolu. U svakoj kontroli ce biti ime dugmeta koje je izabrano.
HTML kod
<!DOCTYPE html>
<html>
<head>
<title>HTML forme</title>
</head>
<body>
<h1>Upotreba dugmadi 2</h1>
<h3>Upotreba dugmadi sa dugmadima tipa Submit</h3>
<form name="forma1" action="php-dugmad-2.php" method="post">
<input type="hidden" name="mojedugme2" value="dugme 1">
<input type="submit" value="Dugme 1">
</form>
<br />
<form name="forma2" action="php-dugmad-2.php" method="post">
<input type="hidden" name="mojedugme2" value="dugme 2">
<input type="submit" value="Dugme 2">
</form>
<br />
<form name="forma3" action="php-dugmad-2.php" method="post">
<input type="hidden" name="mojedugme2" value="dugme 3">
<input type="submit" value="Dugme 3">
</form>
</body>
</html>
Sacuvajte ovaj fajl kao php-dugmad-2.html, u folderu htdocs, foldera xampp. U mom primeru, putanja je C:/xampp2/htdocs/PHPtuts/phpdugme2/php-dugmad-2.html.
Da biste procitali ime dugmeta koje je kliknuto, izvadicete tekst iz skrivene kontrole "mojedugme2":
PHP kod
<!DOCTYPE html>
<html>
<head>
<title>HTML forme</title>
</head>
<body>
<h1>Citanje iz dugmadi 2</h1>
Kliknuli ste na
<?php
if (isset($_POST["mojedugme2"]))
echo $_POST["mojedugme2"], "<br />";
?>
</body>
</html>
Sacuvajte ovaj fajl kao php-dugmad-2.php u istom folderu kao i php-dugmad-2.html.
Rezultat:
If on your web page you make three different HTML forms, each of which should have its own Submit button. When the user selects one of those buttons, data from the form is sent to the PHP script:
<form name="form1" action="php-buttons-2.php" method="post">
<input type="submit" value="Button 1">
</form>
To send data back to the PHP script, you'll add in every form one hidden control. In each control will be the name of the button that was selected.
HTML code
<!DOCTYPE html>
<html>
<head>
<title>HTML forms</title>
</head>
<body>
<h1>Using buttons 2</h1>
<h3>Using buttons with buttons type Submit</h3>
<form name="form1" action="php-buttons-2.php" method="post">
<input type="hidden" name="mybutton2" value="button 1">
<input type="submit" value="Button 1">
</form>
<br />
<form name="form2" action="php-buttons-2.php" method="post">
<input type="hidden" name="mybutton2" value="button 2">
<input type="submit" value="Button 2">
</form>
<br />
<form name="form3" action="php-buttons-2.php" method="post">
<input type="hidden" name="mybutton2" value="button 3">
<input type="submit" value="Button 3">
</form>
</body>
</html>
Save this file as php-button-2.html, in the htdocs folder, of the folder xampp. In my example, the path is C:/xampp2/htdocs/PHPtuts/phpbutton2/php-buttons-2.html.
To read the name of the button that was clicked, you will retrieve a text from a hidden control "mybutton2":
PHP code
<!DOCTYPE html>
<html>
<head>
<title>HTML forms</title>
</head>
<body>
<h1>Reading from buttons 2</h1>
You clicked on
<?php
if (isset($_POST["mybutton2"]))
echo $_POST["mybutton2"], "<br />";
?>
</body>
</html>
Save this file as php-buttons-2.php in the same folder as the php-buttons-2.html.
Result:
<form name="forma1" action="php-dugmad-2.php" method="post">
<input type="submit" value="Dugme 1">
</form>
Da biste podatke poslali nazad do PHP skripta, dodacete u svaku formu po jednu skrivenu kontrolu. U svakoj kontroli ce biti ime dugmeta koje je izabrano.
HTML kod
<!DOCTYPE html>
<html>
<head>
<title>HTML forme</title>
</head>
<body>
<h1>Upotreba dugmadi 2</h1>
<h3>Upotreba dugmadi sa dugmadima tipa Submit</h3>
<form name="forma1" action="php-dugmad-2.php" method="post">
<input type="hidden" name="mojedugme2" value="dugme 1">
<input type="submit" value="Dugme 1">
</form>
<br />
<form name="forma2" action="php-dugmad-2.php" method="post">
<input type="hidden" name="mojedugme2" value="dugme 2">
<input type="submit" value="Dugme 2">
</form>
<br />
<form name="forma3" action="php-dugmad-2.php" method="post">
<input type="hidden" name="mojedugme2" value="dugme 3">
<input type="submit" value="Dugme 3">
</form>
</body>
</html>
Sacuvajte ovaj fajl kao php-dugmad-2.html, u folderu htdocs, foldera xampp. U mom primeru, putanja je C:/xampp2/htdocs/PHPtuts/phpdugme2/php-dugmad-2.html.
Da biste procitali ime dugmeta koje je kliknuto, izvadicete tekst iz skrivene kontrole "mojedugme2":
PHP kod
<!DOCTYPE html>
<html>
<head>
<title>HTML forme</title>
</head>
<body>
<h1>Citanje iz dugmadi 2</h1>
Kliknuli ste na
<?php
if (isset($_POST["mojedugme2"]))
echo $_POST["mojedugme2"], "<br />";
?>
</body>
</html>
Sacuvajte ovaj fajl kao php-dugmad-2.php u istom folderu kao i php-dugmad-2.html.
Rezultat:
If on your web page you make three different HTML forms, each of which should have its own Submit button. When the user selects one of those buttons, data from the form is sent to the PHP script:
<form name="form1" action="php-buttons-2.php" method="post">
<input type="submit" value="Button 1">
</form>
To send data back to the PHP script, you'll add in every form one hidden control. In each control will be the name of the button that was selected.
HTML code
<!DOCTYPE html>
<html>
<head>
<title>HTML forms</title>
</head>
<body>
<h1>Using buttons 2</h1>
<h3>Using buttons with buttons type Submit</h3>
<form name="form1" action="php-buttons-2.php" method="post">
<input type="hidden" name="mybutton2" value="button 1">
<input type="submit" value="Button 1">
</form>
<br />
<form name="form2" action="php-buttons-2.php" method="post">
<input type="hidden" name="mybutton2" value="button 2">
<input type="submit" value="Button 2">
</form>
<br />
<form name="form3" action="php-buttons-2.php" method="post">
<input type="hidden" name="mybutton2" value="button 3">
<input type="submit" value="Button 3">
</form>
</body>
</html>
Save this file as php-button-2.html, in the htdocs folder, of the folder xampp. In my example, the path is C:/xampp2/htdocs/PHPtuts/phpbutton2/php-buttons-2.html.
To read the name of the button that was clicked, you will retrieve a text from a hidden control "mybutton2":
PHP code
<!DOCTYPE html>
<html>
<head>
<title>HTML forms</title>
</head>
<body>
<h1>Reading from buttons 2</h1>
You clicked on
<?php
if (isset($_POST["mybutton2"]))
echo $_POST["mybutton2"], "<br />";
?>
</body>
</html>
Save this file as php-buttons-2.php in the same folder as the php-buttons-2.html.
Result:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.