I know how to write a simple app script that (once published) provide a simple form (name and message) that push values in a Google Spreadsheet.
My question is: how can I run the script from my site? Can I build an html form and when I submit the form writes in a spreadsheet?
Is there a way to "create" a link with values that must be pushed in the spreadsheet?
Where can I find examples?
Thanks
EDIT
GS CODE
var logSheetId = "[SHEETID]"; // Drive ID of log spreadsheet
function doGet(e){
var nome;
var messaggio;
nome = e.parameter.stringaNome;
messaggio=e.parameter.stringaMessaggio;
scriviSpreadsheet(nome,messaggio);
}
function scriviSpreadsheet(nome, messaggio) {
try {
// Open the log and record the new file name, URL and name from form
var ss = SpreadsheetApp.openById(logSheetId);
var sheet = ss.getSheets()[0];
sheet.appendRow([nome, messaggio]);
// Return the new file Drive URL so it can be put in the web app output
//return file.getUrl();
} catch (error) {
return error.toString();
}
}
HTML (external site)
<form id="myForm">
<input type="text" id="nome" name="nome" placeholder="Il tuo nome"/>
<input type="text" id="messaggio" name="messaggio"/>
<input type="button" value="Submit"
onclick="scrivi()" />
</form>
<script>
function scrivi(){
var nome= document.getElementById("nome").value;
var messaggio = document.getElementById("messaggio").value;
var location = "https://script.google.com/macros/s/[MYSCRIPTID]/exec?stringaNome=" + nome + "&stringaMessaggio=" + messaggio;
window.location = location;
}
function onFailure(error) {
alert(error.message);
}
</script>
I know it's not the best code ever but it works.
How can I avoid that any page open when I click the button?