Sunday, August 14, 2011

Process Two Submit Buttons on single Form for different actions

Working with multiple submit form is very useful idea to perform multiple action in single form. For example we can use this structure for Trial and Full Version download, Save and Save Draft,

<?php
if(isset($_POST['download']))
{
	//Choose a File Based on Submit Button	
	if($_POST['download']=="Download Trail Version")
	$file="TrialVersion.exe";
	elseif($_POST['download']=="Download Full Version")
	$file="FullVersion.exe";

	header('Content-type: application/octet-stream');
	header("Content-length:".filesize($file));
	header('Content-Disposition: filename="'.basename($file).'"');		
	readfile($file,true);
	exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

</head>

<body>
<form id="form1" name="form1" method="post" action="<?=$_SERVER['PHP_SELF']?>">

<input type="submit" name="download" value="Download Trail Version" />
<input type="submit" name="download" value="Download Full Version" />

</form>
</body>
</html>

No comments:

Post a Comment