{"action":"created","issue":{"url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server/issues/89","repository_url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server","labels_url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server/issues/89/labels{/name}","comments_url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server/issues/89/comments","events_url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server/issues/89/events","html_url":"https://github.com/dwyl/html-form-send-email-via-google-script-without-server/pull/89","id":214230483,"number":89,"title":"Fix to output checked checkboxes properly as concatenated string","user":{"login":"martynhoyer","id":5610747,"avatar_url":"https://avatars1.githubusercontent.com/u/5610747?v=4","gravatar_id":"","url":"https://api.github.com/users/martynhoyer","html_url":"https://github.com/martynhoyer","followers_url":"https://api.github.com/users/martynhoyer/followers","following_url":"https://api.github.com/users/martynhoyer/following{/other_user}","gists_url":"https://api.github.com/users/martynhoyer/gists{/gist_id}","starred_url":"https://api.github.com/users/martynhoyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/martynhoyer/subscriptions","organizations_url":"https://api.github.com/users/martynhoyer/orgs","repos_url":"https://api.github.com/users/martynhoyer/repos","events_url":"https://api.github.com/users/martynhoyer/events{/privacy}","received_events_url":"https://api.github.com/users/martynhoyer/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2017-03-14T22:52:27Z","updated_at":"2018-02-13T22:49:22Z","closed_at":"2017-03-26T02:57:26Z","author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server/pulls/89","html_url":"https://github.com/dwyl/html-form-send-email-via-google-script-without-server/pull/89","diff_url":"https://github.com/dwyl/html-form-send-email-via-google-script-without-server/pull/89.diff","patch_url":"https://github.com/dwyl/html-form-send-email-via-google-script-without-server/pull/89.patch"},"body":"Just something I noticed while setting this up in a project; if you have a fieldset of checkboxes in your form and the user checks multiples, the data that gets submitted only contains the last checked checkbox value.\r\n\r\nThe fix in this PR creates a string and concatenates the values (with a comma and a space) of each `checked` checkbox within the loop and outputs it at the end (removing the last comma/space along the way).\r\n\r\nThis seems to give the desired result, but a code review/second pair of eyes would be appreciated!"},"comment":{"url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server/issues/comments/365432173","html_url":"https://github.com/dwyl/html-form-send-email-via-google-script-without-server/pull/89#issuecomment-365432173","issue_url":"https://api.github.com/repos/dwyl/html-form-send-email-via-google-script-without-server/issues/89","id":365432173,"user":{"login":"JeremiahMartinez","id":36459966,"avatar_url":"https://avatars3.githubusercontent.com/u/36459966?v=4","gravatar_id":"","url":"https://api.github.com/users/JeremiahMartinez","html_url":"https://github.com/JeremiahMartinez","followers_url":"https://api.github.com/users/JeremiahMartinez/followers","following_url":"https://api.github.com/users/JeremiahMartinez/following{/other_user}","gists_url":"https://api.github.com/users/JeremiahMartinez/gists{/gist_id}","starred_url":"https://api.github.com/users/JeremiahMartinez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JeremiahMartinez/subscriptions","organizations_url":"https://api.github.com/users/JeremiahMartinez/orgs","repos_url":"https://api.github.com/users/JeremiahMartinez/repos","events_url":"https://api.github.com/users/JeremiahMartinez/events{/privacy}","received_events_url":"https://api.github.com/users/JeremiahMartinez/received_events","type":"User","site_admin":false},"created_at":"2018-02-13T22:49:22Z","updated_at":"2018-02-13T22:49:22Z","author_association":"NONE","body":"Hi, I created an account just for this issue.  I tried using martynhoyer's fix but my spreadsheet is still only showing the first box checked, not concatenating them as a string.  The objective of this code is for the user to select checkboxes for email recipients.  I'd like the values to be strung together seperated by a semicolon and space, then used as the To: in the MailApp.sendEmail.\r\nThis is how I have my form written:\r\n` <form id=\"gform\" method=\"POST\" class=\"pure-form pure-form-stacked\"\r\n  action=\"https://script.google.com/macros/s/AKfycbyvPwb-PV-XigKRMQj9k0YD1w6KaMNT2GuvYbgCO9lKGU3_bgDv/exec\">\r\n\r\n    <fieldset>\r\n    <label for=\"personal\" class=\"pure-checkbox\">\r\n        <input id=\"personal\" type=\"checkbox\" name=\"email[]\" value=\"my_email@private_account.com\">\r\n        Gmail\r\n    </label>\r\n    \r\n    <label for=\"business\" class=\"pure-checkbox\">\r\n        <input id=\"work\" type=\"checkbox\" name=\"email[]\" value=\"my_email@work_account.com\">\r\n        Business\r\n    </label>\r\n    </fieldset>\r\n     <fieldset class=\"pure-group\">\r\n      <label for=\"message\">Comment: </label>\r\n      <textarea id=\"message\" name=\"message\" rows=\"10\"\r\n      placeholder=\"(Optional)\"></textarea>\r\n    </fieldset>\r\n\r\n     <button class=\"button-success pure-button button-xlarge\">\r\n      <i class=\"fa fa-paper-plane\"></i>&nbsp;Send</button>\r\n\r\n  </form>`\r\n\r\nAnd the function getFormData() is written:\r\n`function getFormData() {\r\n  var form = document.getElementById(\"gform\");\r\n  var elements = form.elements; // all form elements\r\n  var fields = Object.keys(elements).map(function(k) {\r\n    if(elements[k].name !== undefined) {\r\n      return elements[k].name;\r\n    // special case for Edge's html collection\r\n    }else if(elements[k].length > 0){\r\n      return elements[k].item(0).name;\r\n    }\r\n  }).filter(function(item, pos, self) {\r\n    return self.indexOf(item) == pos && item;\r\n  });\r\n  var data = {};\r\n   fields.forEach(function(k){\r\n     data[k] = elements[k].value;\r\n    var str = \"\";\r\n     if(elements[k].type === \"checkbox\"){\r\n      //data[k] = elements[k].checked;  //Apparently this is supposed to be removed\r\n      str = str + elements[k].checked + \"; \";\r\n      data[k] = str.slice(0, -2);\r\n    }else if(elements[k].length){\r\n       for(var i = 0; i < elements[k].length; i++){\r\n         if(elements[k].item(i).checked){\r\n          //data[k] = elements[k].item(i).value;   //Apparently this is also supposed to be removed\r\n          str = str + elements[k].item(i).value + \", \";\r\n          data[k] = str.slice(0, -2);\r\n         }\r\n       }\r\n  }});\r\n\r\n  // add form-specific values into the data\r\n  data.formDataNameOrder = JSON.stringify(fields);\r\n  data.formGoogleSheetName = form.dataset.sheet || \"responses\"; // default sheet name\r\n  data.formGoogleSendEmail = form.dataset.email || \"\"; // no email by default\r\n\r\n  console.log(data);\r\n  return data;\r\n}`\r\n\r\nFor now, I've set my own email as the TO_ADDRESS just to monitor string results.  In that email, I do see both checked items as a string seperated by a comma.  The email looks like this:\r\n\r\n> email[]\r\nmy_email@private_account.com,my_email@work_account.com\r\nmessage\r\nThis is a test.\r\n\r\nAny suggestions?  Thank you!!"}}
{"actor":{"display_login":"JeremiahMartinez"}}