Last active
April 18, 2016 07:55
-
-
Save khaeransori/5d0d8ac843dffffe72def6c3e62983bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// if form submitted | |
if (!empty($_POST)) : | |
// get all posted variable | |
$lamp = $_POST['lamp']; | |
$blower = $_POST['blower']; | |
// TODO : generate content based on variables | |
$content = '.txt file content editted'; | |
// create file container | |
$fileName = 'myText.txt'; | |
$writingMode = 'wa+'; //listed here http://php.net/manual/en/function.fopen.php | |
$fp = fopen(getcwd() . "/" . $fileName, $writingMode); | |
// write content to file | |
fwrite($fp, $content); | |
fclose($fp); | |
// redirect to form | |
header("Refresh:0"); | |
// TODO : add message if fail or sucess | |
else : | |
// if not submitted yet, then show form | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Form</title> | |
</head> | |
<body> | |
<form method="post" action=""> | |
<div class="form-group"> | |
Blower : <select name="blower"> | |
<option value="0">Off</option> | |
<option value="0">On</option> | |
</select> | |
</div> | |
<div class="form-group"> | |
Lamp : <select name="lamp"> | |
<option value="0">Off</option> | |
<option value="0">On</option> | |
</select> | |
</div> | |
<button type="submit">GENERATE</button> | |
</form> | |
</body> | |
</html> | |
<?php | |
endif; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment