1

I am sending through a form object to Google Apps Script with:

var formObject = $("#my_form")[0];

google.script.run.processForm(formObject)

The form includes a file input and I have no problem retrieving this and the other input values on the server with something like:

function processForm(formObject) {
  var user_name = formObject.userNameInputName;
}

The documentation is clear that GAS can send through a form providing it is the only parameter:

https://developers.google.com/apps-script/guides/html/reference/run#myFunction(...)

My question is:

How do I access a data attribute value of a form input server side?

And to answer this I need to ask a silly question:

What is a "form object"? What is it's structure, what does it "look like" - is it just a JavaScript object or something else? (if I console.log(formObject) client side it just displays the HTML). If I know this I figure I will know how to access the data attribute value correctly.

Edit:

I ended up just adding a hidden input field to the form and setting the val() of it via an on click event before submitting the form, then I could access the value server side with:

function processForm(formObject) {
  var user_name = formObject.userNameInputName;
  var was_a_data_attribute = formObject.myHiddenInputField;
}
Rubén
  • 34,714
  • 9
  • 70
  • 166
user1063287
  • 10,265
  • 25
  • 122
  • 218
  • 3
    Apps Script sends a totally different object to the server, not the real Form Element. You can't get HTML attributes out of that object server side, because all that information is not in the object sent to the server. I believe that HTML elmnts are basically JSON objects, but I'm not 100% sure on that. You would need to get the HTML information that you need before sending the data to the server. You can `JSON.stringify(object)` objects before sending them to the server, if that helps. So, `JSON.stringify(object)` converts the object to a string. You could try doing that to the Form El. – Alan Wells Dec 12 '16 at 16:28
  • I will try this tomorrow (on mobile now), my considerations/limitations are that only one function parameter is allowed when passing a form object (as in link above), and I need to pass through a file. So if I can do that with stringify that will be great. – user1063287 Dec 12 '16 at 16:33
  • 1
    Does this [answer](http://stackoverflow.com/questions/15670392/uploading-file-using-google-apps-script-using-htmlservice) your question? – DDD Dec 12 '16 at 16:56
  • Does this answer your question? [Uploading file using Google Apps Script using HtmlService](https://stackoverflow.com/questions/15670392/uploading-file-using-google-apps-script-using-htmlservice) – Rubén Sep 01 '20 at 02:28

0 Answers0