I finally am at the finals steps of my app and there's just one thing I cannot figure out how to write: I'm using an iframe to load a page in Google Apps Script in which I have a form.
I'm able to write data in a Google Spreadsheet and I get a successful message if data are correctly inserted. The only thing I cannot get is how to make refresh the frame after a few seconds to be sure the user read the message...
Any help?
Thanks a lot!
That's my code (credits to @Cooper for helping me A LOT with this - he basically wrote the code)
<body>
<div id="errorMessage" style="display:none;">
<h3>Errore</h3>
<p>Tutti i campi devono essere compilati.</p></div>
<div id="data">
<form name="reqForm" id="reqForm" method="post" action="" accept-charset="UTF-8">
<label for="area">* Area</label>
<select id="area">
<option value="">--Seleziona--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<br />
<label for="nome">* Oggetto:</label>
<input type="text" id="oggetto" name="oggetto" />
<br />
<br />
<label for="nome">* Nome:</label>
<input type="text" id="nome" name="nome" />
<br />
<label for="cognome">* Cognome:</label>
<input type="text" id="cognome" name="cognome" />
<br />
<label for="mat">Matricola:</label>
<input type="text" pattern="[0-9]{6}" id="mat" name="mat" />
<br />
<label for="mail">* E-mail:</label>
<input type="mail" id="mail" name="mail"/>
<br />
<label for="testo">* Richiesta:</label>
<textarea id="testo" name="testo"></textarea>
<br />
<button type="button" value="Invia" id="btnSend" class="button mainBtn">Invia</button>
</form>
</div>
<div id="resp" style="display:none;">
<h3>Inviato</h3>
<p>I tuoi dati sono stati registrati.<br/>Riceverai risposta all'indirizzo indicato.</p>
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function() {
$('#btnSend').click(validate);
});
function setResponse(a)
{
if(a)
{
$('#data').css('display','none');
$('#resp').css('display','block');
}
}
function validate()
{
var area = document.getElementById('area').value;
var n = document.getElementById('nome').value;
var c = document.getElementById('cognome').value;
var m = document.getElementById('mat').value;
var em= document.getElementById('mail').value;
var t = document.getElementById('testo').value;
var o = document.getElementById('oggetto').value;
var a = [n, c, m, em, area, o, t, "", "Ricevuta"];
if(area && n && c && em && o && t)
{
google.script.run
.withSuccessHandler(setResponse)
.getData(a);
$('#errorMessage').css('display','none');
return true;
}
else
{
$('#errorMessage').css('display','block');
}
}
function loadTxt(from,to)
{
document.getElementById(to).value = document.getElementById(from).value;
}
console.log('My Code');