Last active
February 2, 2022 06:10
-
-
Save neno-tech/b0b30521ec31f46d981a4fe514684325 to your computer and use it in GitHub Desktop.
ฟอร์มบันทึกลงชีตด้วยวิธี doPost
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
function doGet(e) { | |
var htmlOutput = HtmlService.createTemplateFromFile('index'); | |
var courses = getCourses() | |
htmlOutput.message = '' | |
htmlOutput.courses = courses | |
return htmlOutput.evaluate() | |
} | |
function doPost(e) { | |
var name = e.parameters.name.toString(); | |
var courses = e.parameters.courses.toString(); | |
AddRecord(name, courses); | |
var htmlOutput = HtmlService.createTemplateFromFile('index'); | |
var courses = getCourses(); | |
htmlOutput.message = 'ลงทะเบียนเรียบร้อยแล้ว'; | |
htmlOutput.courses = courses; | |
return htmlOutput.evaluate() | |
} | |
function AddRecord(name, courses) { | |
var ss = SpreadsheetApp.getActive().getSheets()[0] | |
ss.appendRow([name, courses, new Date()]) | |
} | |
function getCourses() { | |
var ss = SpreadsheetApp.getActive().getSheets()[1] | |
var array = [] | |
for (var i = 2; i< ss.getLastRow()+1; i++) { | |
array.push(ss.getRange(i,1).getValue()) | |
} | |
return array; | |
} | |
function getUrl() { | |
var url = ScriptApp.getService().getUrl(); | |
return url; | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<base target="_top"> | |
<style>*{font-family:Prompt}</style> | |
</head> | |
<body> | |
<h1>ฟอร์มลงทะเบียน</h1> | |
<?var url = getUrl()?> | |
<form method="post" action="<?= url ?>"> | |
<label style="font-size:20px">ชื่อ สกุล</label><br> | |
<input type="text" name="name" style="font-size: 20px"><br><br> | |
<label style="font-size:20px" > เลือกคอร์ส </label><br> | |
<select name="courses" style="font-size: 20px" > | |
<option value="" ></option> | |
<? for(var i=0; i< courses.length; i++) { ?> | |
<option value="<?= courses[i] ?>" ><?= courses[i] ?></option> | |
<? } ?> | |
</select> | |
<br><br> | |
<input type="submit" name="submitButton" value="ลงทะเบียน" style="font-size: 20px"> | |
<span style-="font-size: 20px" ><?= message ?></span> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment