Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:28:33+00:00 2026-06-17T08:28:33+00:00

UPDATE: Added doGet function. I have a web app that is used for a

  • 0

UPDATE: Added doGet function.

I have a web app that is used for a registration process. I created an email confirmation that sends the user an email when they click the Register button.

My question is, how do I stop the function from running if the email field is left blank? At this point when I run the whole script, an error message is shown when I click register if I don’t enter an email address. I don’t want the function to throw an error and I want to be able to still register.

function doGet(e) {
 var app = UiApp.createApplication().setTitle('Education Registration');
  app.setStyleAttribute("background", "#DBE8C4");
var panel1 = app.createAbsolutePanel().setId('panel1');
  panel1.setHeight(900);
  panel1.setWidth(1500);

  //Register button

var dateSelection = app.createButton('Register').setSize(140, 40);
var loadingWait = app.createLabel('After clicking Register, please allow 5 - 30 seconds for the webpage to process the request.');
var clickHandler = app.createServerHandler("respondToDateSelection");
  dateSelection.addClickHandler(clickHandler);
  clickHandler.addCallbackElement(panel1);

//Email Handler
var emailHandler = app.createServerHandler("emailConfirmation");
  dateSelection.addClickHandler(emailHandler);
  emailHandler.addCallbackElement(panel1);

  return app;

}


function emailConfirmation(e) {
 var app = UiApp.getActiveApplication();

  app.getElementById('fNameText1');
  app.getElementById('lNameText1');
  app.getElementById('eAddressText1');
  app.getElementById('dataItemsLB');
  app.getElementById('aemailAddressText');

  var fNameText1 = e.parameter.fNameText1;
  var lNameText1 = e.parameter.lNameText1;
  var eAddressText1 = e.parameter.eAddressText1;
  var dataItemsLB = e.parameter.dataItemsLB;
  var aemailAddressText = e.parameter.aemailAddressText;

  var subject = "Class Registration Confirmation - " + fNameText1 + " " + lNameText1;
  var emailBody = "This is an Email Confirmation.";

            MailApp.sendEmail(eAddressText1, subject,
                 emailBody, {cc: aemailAddressText});


  return app;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:28:34+00:00Added an answer on June 17, 2026 at 8:28 am

    There are many ways to do that, the most “elegant” way would probably be using a client handler validator in your doGet function but you didn’t show it …(there is a specific validator for emails)
    Another way is to have a warning label in your UI that is initially invisible and that gets visible when e.parameter.eAddressText1 is not a valid email or is empty, the same condition would apply to the sendEmail command and skip it if not valid then return to the UI.

    feel free to post your doGet function to allow for more accurate answer.


    EDIT :
    thanks for posting your code, although it was incomplete and needed some work to make it an interesting example, I end up with this code to illustrate the use of clientHandlers, validators and try/catch for email adress…

    Here is the code, I changed it to work on a spreadsheet to avoid deploying and versioning, it is just a test, nothing more…

    function doGet(e) {
     var app = UiApp.createApplication().setTitle('Education Registration');
      app.setStyleAttribute("background", "#DBE8C4");
      var panel0 = app.createFlowPanel().setId('panel0');
      var panel1 = app.createVerticalPanel().setId('panel1');
      var fNameText1=app.createTextBox().setName('fNameText1').setId('fNameText1');;
      var lNameText1=app.createTextBox().setName('lNameText1').setId('lNameText1');;
      var eAddressText1=app.createTextBox().setName('eAddressText1').setId('eAddressText1').setText('mail')
      var dataItemsLB=app.createTextBox().setName('dataItemsLB').setId('dataItemsLB');;
      var aemailAddressText=app.createTextBox().setName('aemailAddressText').setId('aemailAddressText').setText('mail');
      panel1.add(fNameText1).add(lNameText1).add(eAddressText1).add(dataItemsLB).add(aemailAddressText)
      panel0.add(panel1)
    
    //Register button
      var dateSelection = app.createButton('Register').setSize(140, 40).setId('dateSelection');
      var loadingWait = app.createLabel('After clicking Register, please allow 5 - 30 seconds for the webpage to process the request.').setVisible(false).setId('loadingWait');
      var clickHandler = app.createServerHandler("respondToDateSelection").validateEmail(eAddressText1);
      dateSelection.addClickHandler(clickHandler);
      clickHandler.addCallbackElement(panel0);
    
    //Email Handler
      var emailHandler = app.createServerHandler("emailConfirmation").validateEmail(eAddressText1);
      dateSelection.addClickHandler(emailHandler);
      emailHandler.addCallbackElement(panel1);
    
    //client handlers
      var warning = app.createLabel('Please enter your email where necessary').setId('warning').setVisible(false).setStyleAttribute('background','yellow')
      var clientHandlerwait = app.createClientHandler().forTargets(loadingWait).setVisible(true).validateEmail(eAddressText1)
      var clientHandler1 = app.createClientHandler().validateNotEmail(eAddressText1)
        .forTargets(warning).setVisible(true).forEventSource().setStyleAttribute('color','red')
      var clientHandler2 = app.createClientHandler().validateNotEmail(aemailAddressText)
        .forTargets(warning).setVisible(true).forEventSource().setStyleAttribute('color','red')
    
      dateSelection.addClickHandler(clientHandlerwait).addClickHandler(clientHandler1).addClickHandler(clientHandler2)
    
      app.add(panel1.add(dateSelection).add(loadingWait).add(warning))
      SpreadsheetApp.getActive().show(app)
    //  return app;
    }
    
    function respondToDateSelection(){
    return
    }
    
     function emailConfirmation(e) {
      var app = UiApp.getActiveApplication();
       app.getElementById('warning').setVisible(false);
       app.getElementById('dateSelection').setStyleAttribute('color','black')
    
      var fNameText1 = e.parameter.fNameText1;
      var lNameText1 = e.parameter.lNameText1;
      var eAddressText1 = e.parameter.eAddressText1;
      var dataItemsLB = e.parameter.dataItemsLB;
      var aemailAddressText = e.parameter.aemailAddressText;
      var subject = "Class Registration Confirmation - " + fNameText1 + " " + lNameText1;
      var emailBody = "This is an Email Confirmation.";
        try{
    //            MailApp.sendEmail(eAddressText1, subject,emailBody, {cc: aemailAddressText});
            Utilities.sleep(500)// simulate a duration to read the message
            app.getElementById('loadingWait').setText('mail sent').setVisible(true)
    }catch(err){
            app.getElementById('loadingWait').setText('error sending mail').setVisible(true)
    }
      return app;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update Added jsfiddle - see bottom of post I currently have a function that
Update: I've added an answer that describes my final solution (hint: the single Expr
There're files/folders that were deleted and then re-added to the repository. svn update >
Update: Added Schema to the bottom... I have a table of contracts: tbl_contract And
I'm trying to change an app theme at run time so I have added
I have created a new WPF application and added an event handler for Loaded
Update : Added simple test example http://jsfiddle.net/7UhrW/1/ using normalize.css. Chrome/WebKit and Firefox have different
update I added a metabox using http://codex.wordpress.org/Function_Reference/add_meta_box Unfortunatly it only adds the metabox to
I added a counter cache but can't get it to update. But I can
NOTE: I added my new solution at the UPDATE answer below. I try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.