0
votes

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');

1
I'd need to know a little more about what your doing before I could help. Can you share your code and spreadsheet?Cooper
@Cooper Hi you! The code is the same you helped me before, I'll edit my question and post it in a few secondsSimone
@Cooper I edited the question with the code. Basically I have to reload this page after the message is shown (Inviato etc.), waiting a few second to make the user read it.Simone
I don't really understand what your saying here: 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...Cooper
I tested my app: once I send the message, I can keep navigate my pages but if I'd like to sent another request, I see the confirmation message and not the form. I think that's because I'm using jQuery Mobile and I don't have different pages but just ONE HTML page, so I need the script to reload the formSimone

1 Answers

0
votes

Okay. Well I think that's it. You just have to refresh the page. You could put a button on there that says submit another form which would just refresh the page. I suppose you could use Javascript Timer to refresh the page 10 seconds after setResponse();