javascript - How do I export Google Script form data to Google Drive? -


i have built simple form in google scripts. file upload feature functional: uploads file google drive. cannot figure out how grab form information (name, organization, content type), save spreadsheet, , upload google drive.

how upload form data (text fields) drive?

!!update 7/19!! code updated spreadsheet app code. , improved html. css not included don't think it's relevant issue.

!!update 7/20!! code working. updated reflect full functionality. sandy assistance.

form.html

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=montserrat:400"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">  <div id="main">  <div class="form">   <form id='myform'>       <div class="header">         <h1>information submission form</h1>         <h2>center alternative fuels</h2>       </div>        <div class="row">        <div class="col-md-6">          <input id='name' type="text" name="name" placeholder="full name" class="full item" spellcheck="false">       </div>        <div class="col-md-6">          <input id='email' type="text" name="email" placeholder="email" class="full item" spellcheck="false">       </div>      </div>       <div class="row indent item">       <input id='organization' type="text" name="organization" placeholder="organization" class="full" spellcheck="false">      </div>       <div class="row indent item">        <textarea id='type' name="type" class="full" placeholder="what submitting? (presentation, educational content,...)" rows='2'></textarea>      </div>       <div id='success'>      </div>        <div class="row indent item">        <textarea id='info' name="info" class="full" placeholder="describe content submitting" rows='8'></textarea>      </div>        <input type="file" name="myfile">      <input type="submit" value="submit"         onclick="this.value='uploading..';             google.script.run.withsuccesshandler(fileuploaded)             .uploadfiles(this.parentnode);             return false;" style="margin-top: 20px">   </form>  </div> </div>  <div id="output"></div>  <script>  function fileuploaded(status) {      document.getelementbyid('myform').style.display = 'none';      document.getelementbyid('output').innerhtml = status;  } </script> 

server.gs

function doget(e) {   return htmlservice.createhtmloutputfromfile('form.html'); }  var url;  function uploadtosheet(form){   var fullname, emailadd, organization, filetype, fileinfo;   var ss = spreadsheetapp.openbyid("insert sheet id here");   var dataarray = [];   fullname = form.name;  emailadd = form.email;  organization = form.organization;  filetype = form.type;  fileinfo = form.info;   dataarray.push(fullname);  dataarray.push(emailadd);  dataarray.push(organization);  dataarray.push(filetype);  dataarray.push(fileinfo);   ss.appendrow('dataarray');  }  function uploadfiles(form) {  try {    var dropbox = "form files";   var folder, folders = driveapp.getfoldersbyname(dropbox);  if (folders.hasnext()) {   folder = folders.next(); }  else {   folder = driveapp.createfolder(dropbox); }    var blob = form.myfile;       var file = folder.createfile(blob);       file.setdescription("uploaded " + form.myname);   url=file.geturl();    return "file uploaded " + file.geturl(); }   catch (error) {   return error.tostring();   } } 

the code might this:

var dataarray,org,ss,username;  ss = spreadsheetapp.openbyid("spreadsheet_file_id"); dataarray = [];  username = form.myname; org = form.myorganization;  dataarray.push(username); dataarray.push(org);  ss.appendrow(dataarray); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -