0

I have a google sheet, and I want to get HTML form data in that google sheet. The google sheet has 4 columns.

  1. Voucher Code
  2. Name
  3. Email
  4. Phone number

Voucher code column is already filled with voucher codes.

And in the HTML form, person will fill the voucher code, name, email and Phone number. Voucher code will match the voucher code column and data of name, email and phone number will be filled in the same row. Now here I have to check the validation. If the voucher code, already has name, email and phone number. Then there should give a error message that already someone is there on that voucher code. And if the name, email and phone number column is empty for any voucher code. Then only the html form data should go.

Please help me regarding this.

Thank you

Salman
  • 1
  • 2
  • Share your code. And yes, it is possible. – Neven Subotic Feb 21 '22 at 20:42
  • @NevenSubotic I only have the code to get and post the data from sheet. How to validate it and check. That i want to know. – Salman Feb 21 '22 at 22:19
  • Take a look at this https://stackoverflow.com/a/60365261/7215091 it's not exactly what you want but it's close enouh that you should be able to figure it out – Cooper Feb 22 '22 at 02:23
  • @Cooper it's not even closer to that. – Salman Feb 22 '22 at 05:12
  • Perhaps not but it uses a mutli field form and stores data on a spreadsheet. If you want something exact perhaps you should hire someone to do it for you. – Cooper Feb 22 '22 at 05:36
  • Welcome to [so]. Please add more details about your HTML form. What are you using to make your "HTML form" to be online? Are you using the HTML Service from Google Apps Script? – Rubén Feb 22 '22 at 05:39

1 Answers1

0

So if you want the front-end (the person filling out the form in their browser) to communicate with the back-end (your code and database) then it is best you the documentation. Based on your requirements, you will be sending a response back to the client after they have filled out the form. So in your form handler function, in the back-end you want to do all the checking and then provide a response.

Here is also an example with forms and client server communication.

So a simple example is

function formHandler(e){
  const voucherIdFromForm = e.voucherId

  const vouchers = SpreadsheetApp.getActive().getSheetByName("Vouchers").getRange("A2:A").getValues().flat()

 // lets look into the array and see if the voucher is new
 if( vouchers.indexOf( voucherIdFromForm ) == -1 ){
   // here you can get add in the name to the corresponding voucher
   return true
 } else {
   // Already exists
   return false
 }
}
Neven Subotic
  • 1,399
  • 1
  • 6
  • 18