Using Submit buttons to invoke PHP actions
Posted: Wed Nov 19, 2008 10:17 pm
I've been reading and playing with forms and submit buttons. What I would like to do is have "next" and "previous" submit buttons and then POST which button the user clicked. But without user input. Is there a better way to do this besides using 2 forms and two submit buttons for next and previous? The code below works, but it seems kludgy. Is there a more "standard" way to do this? Also, how would I get the two buttons to appear next to each other?
Thank you for any pointers and cleverness!
HTML Side
PHP Side:
Thank you for any pointers and cleverness!
HTML Side
Code: Select all
<!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>Untitled Document</title>
</head>
<body>
<div>
<form action="But2.php" method="post">
<INPUT TYPE="hidden" name="button" value="next">
<input type="submit" value="Next">
</form>
<form action="But2.php" method="post">
<input type="hidden" name="button" value="previous">
<input type="submit" value="Previous">
</form>
</div>
</body>
</html>Code: Select all
<?php
if ($_REQUEST["button"] == "next") print "in next</b><br/>\n\n";
if ($_REQUEST['button'] == "previous") print "in previous</b><br/>\n\n";
?>