Google Sites‎ > ‎Sample Scripts‎ > ‎

Uiapp form with email

Here is a code snippet showing the general principles for creating a form with an email handler using Google Apps scripts uiapp



It looks something like...

function doGet(e) {
  var app = UiApp.createApplication();
 
  //create the form panel
  var form = app.createFormPanel().setId('form')
  var panel = app.createAbsolutePanel().setSize('400','400')
  form.setWidget(panel)      
  app.add(form);

  ... // Add various text boxes and labels
   
  panel.add(app.createSubmitButton("Submit"),331,370)
  
  var handler = app.createServerSubmitHandler("onFormSubmit") 
  form.addSubmitHandler(handler)
    
  return app;
}

function onFormSubmit(e) {
      
  try {
      var p = e["parameter"]             
      var subject = p["subject"]
      var email   = p["email"]
      var message = p["message"]

          MailApp.sendEmail("*********", subject, "From "+email+"\n\n"+message)
    
  }
  catch (ex) {
      MailApp.sendEmail("*********", "Form submit fail",ex.toString()+"\n\n"+objtostring(e))        
  }
  return true 
}
Comments