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 9115889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:32:25+00:00 2026-06-17T04:32:25+00:00

I have a form with five elements, firstName , lastName , username , password

  • 0

I have a form with five elements, firstName, lastName, username, password and passwordConfirmation

var errors = [];
var errorsText = [];


function generateError(messageText, elementIdentifier) {
var messageText = messageText;
var elementIdentifier = elementIdentifier;
errors.push(elementIdentifier);
errorsText.push(messageText);
return false;
}



function validateRegistrationForm(firstName, lastName, username, password, passwordConfirmation) {
formReset();
//alert("validateRegistrationForm() has been called");

var firstName = firstName;
//alert("First Name = \'" + firstName + "\'");
var lastName = lastName;
//alert("Last Name = \'" + lastName + "\'");
var username = username;
//alert("Username = \'" + username + "\'");
var password = password;
//alert("Password = \'" + password + "\'");
var passwordConfirmation = passwordConfirmation;
//alert("Password Confirmation = \'" + passwordConfirmation + "\'");

if ( ( firstName == null ) || ( firstName == "" ) ) {
    //alert("//firstname hasn't been filled out");

    generateError("You must provide a First Name", "firstName");
} 

if ( ( lastName == null ) || ( lastName == "" ) ) {
    //lastname hasn't been filled out
    generateError("You must provide a Last Name", "lastName");
}

if ( ( username == null ) || ( username == "" ) ) {
    //username hasn't been filled out
    generateError("You must enter a Username", "username");
}

if ( ( password == null ) || ( password == "" ) ) {
    //password hasn't been filled out
    generateError("You haven\'t entered a password", "password");
}

if ( ( passwordConfirmation == null ) || ( passwordConfirmation == "" ) ) {
    //passwordconfirmation hasn't been filled out
    generateError("You haven\'t confirmed your password", "passwordConfirmation");
}

validatePassword(password, passwordConfirmation);

}

Is there a better way to handle all of the if statements?

  • 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-17T04:32:27+00:00Added an answer on June 17, 2026 at 4:32 am

    This looks like something you could use the Logical OR short circuit for

    function validateRegistrationForm(firstName, lastName, username, password, passwordConfirmation) {
        formReset();
        firstName || generateError("You must provide a First Name", "firstName");
        lastName || generateError("You must provide a Last Name", "lastName");
        username || generateError("You must enter a Username", "username");
        password || generateError("You haven\'t entered a password", "password");
        passwordConfirmation || generateError("You haven\'t confirmed your password", "passwordConfirmation");
        validatePassword(password, passwordConfirmation);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a form with five <input type=file/> elements that is in production and
I have five buttons on one form that when clicked enables a bool each
I have a formset that contains five forms. Each form is simply a file
I have a page with a form that contains five selects (drop-down lists) which
I have a DLL with one single function That gets five doubles and one
Basically i have a form with around 100 elements. The values bind to my
I have a form which have five buttons and several checkboxes holding different values.
I have a form that save a question and five answers in the database
I have an application containing a form with five input fields. When the user
I have a simple form: function mymodule_test_form(&$form_state, $nid) { form['submit'] = array( '#type' =>

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.