0

I have a simple form inside an iFrame submitting to GAS Web App:

<form action="https://script.google.com/macros/s/AK...a4/exec" method="POST">
    Name:<br>
    <input type="text" name="name">
    <br>
    Email:<br>
    <input type="email" name="email" value="">
    <br><br>
    <input type="hidden" name="product" value="Inv">
    <input type="submit" value="DOWNLOAD" style="margin:0px auto; display:block; width: 10em;  height: 2.4em;">
</form>

I want to send back to the iFrame a message from the doPost service, for example:

function doPost(e) {
...
var response = "<HTML><BODY><H1>Error processing request</H1><BR><BR><P>Missing or invalid parameter in request.</P></BODY></HTML>"
   return ContentService.createTextOutput(response).setMimeType(ContentService.MimeType.TEXT); 
}

However, the iFrame is cleared empty after the submit, and never displays my message. What am I missing?

Thanks!

Mor Sagmon
  • 905
  • 1
  • 16
  • 35

1 Answers1

0

As detailed in the documentation, use createTextOutput(content) method to create a new TextOutput object that can serve the given content. Try using this sample code:

function doGet() {
    var output = ContentService.createTextOutput("Hello world!");
    return output;
}

To further use your code, try also removing HTML tags within your doPost() function and see if it works.

Lastly, please also check solution given in this SO post - HTML Form does not submit to spreadsheet using doPost. It might also help.

Community
  • 1
  • 1
adjuremods
  • 2,938
  • 2
  • 12
  • 17
  • Thanks! I implemented an XMLHttpRequest against a doGet in GAS, as per the example link you provided - the client iFrame receives no response. Apparently it is a known unsupported feature by Google: https://code.google.com/p/google-apps-script-issues/issues/detail?id=1563 it seems I have no way to implement a two-way HTTP communication here... – Mor Sagmon Oct 03 '16 at 12:43
  • I also tried implementing with JSONP but the response does not pass through to the browser, probably because of google redirect. https://developers.google.com/apps-script/guides/content#serving_jsonp_in_web_pages – Mor Sagmon Oct 03 '16 at 14:18