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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:40:59+00:00 2026-06-19T01:40:59+00:00

I’m learning, trying to create a simple web form, validate the form data, and

  • 0

I’m learning, trying to create a simple web form, validate the form data, and pass the data to a php file.

After all of the field values are validated, they are not being passed to the php file.

<form action="/xxxxx.php" method="post" name="registration" onsubmit="return formValidation();">

I’ve change the form name to anything else…

<form action="/xxxxx.php" method="post" name="anythingelse" onsubmit="return formValidation();">

…the form works (without validation) and the field values are being passed to the php file. I’m receiving the completed form, so I know without validation the web form is working correctly.

So it would appear as though there is something wrong with the validation, I.E. the function(s) are returning false even after all functions have passed validation and presumably returned true.

Or something else is wrong. I don’t understand what’s wrong? I’d appreciate any help.

Here’s the code.

    <script type="text/javascript">
        function formValidation() {
            var uname = document.registration.username;
            var uadd = document.registration.city;
            var ucountry = document.registration.country;
            var uzip = document.registration.zip;
            var uemail = document.registration.email;
            var uphone = document.registration.phone;
            {
                if (allLetter(uname)) {
                    if (alphanumeric(uadd)) {
                        if (countryselect(ucountry)) {
                            if (allnumeric(uzip)) {
                                if (ValidateEmail(uemail)) {
                                    if (validatePhone(uphone)) {
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return false;

        }

        function validatePhone(uphone) {
            var letters = /^[0-9a-zA-Z-]+$/;
            if (uphone.value.match(letters)) {
                return true;
            }
            else {
                alert('Phone Number [Required]: Please enter your phone number (use this format, xxx-xxx-xxxx)');
                uphone.focus();
                return false;
            }
        }
        function allLetter(uname) {
            var letters = /^[A-Za-z ]+$/;
            if (uname.value.match(letters)) {
                return true;
            }
            else {
                alert('Full Name [Required]: Please enter your full name (alphabet characters only)');
                uname.focus();
                return false;
            }
        }
        function alphanumeric(uadd) {
            var letters = /^[0-9a-zA-Z ]+$/;
            if (uadd.value.match(letters)) {
                return true;
            }
            else {
                alert('City [Required]: Please enter your city (alphabet characters only)');
                uadd.focus();
                return false;
            }
        }
        function countryselect(ucountry) {
            if (ucountry.value == "Default") {
                alert('State [Required]: Please select your State from the drop down list');
                ucountry.focus();
                return false;
            }
            else {
                return true;
            }
        }
        function allnumeric(uzip) {
            var numbers = /^[0-9]+$/;
            if (uzip.value.match(numbers)) {
                return true;
            }
            else {
                alert('ZIP code [Required]: Please enter your Zip Code (numbers only, use this format xxxxx)');
                uzip.focus();
                return false;
            }
        }
        function ValidateEmail(uemail) {
            var mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
            if (uemail.value.match(mailformat)) {
                return true;
            }
            else {
                alert('Email Address [Required]: You have entered an invalid email address. Please verify and correct your email address.');
                uemail.focus();
                return false;
            }
        }

    </script>
    <form name="registration" action="/xxxxxx.php" method="post" onsubmit="return formValidation();">
    <input type="hidden" name="subject" value="xxxxx - Contact" />
    <input type="hidden" name="redirect" value="confirmation.html" />
    <div>
        <strong>Email Address [Required]:</strong>
        <input type="text" name="email" size="50" title="Please enter your email address" />
    </div>
    <div>
        <span><strong>Company Name [Optional]:</strong></span> <span>
            <input type="text" id="companyName" name="companyName" size="50" title="Please enter your company name" /></span>
    </div>
    <div>
        <span><strong>Full Name:</strong></span> <span>
            <input type="text" id="username" name="username" size="30" title="Please enter your full name" /></span>
    </div>
    <div>
        <span><strong>Phone Number:</strong></span> <span>
            <input type="text" id="phone" name="phone" size="17" title="Please enter your phone number" /></span>
        <br />
        <span><strong>Phone Ext. [Optional]:</strong></span> <span>
            <input type="text" id="phoneExtn" name="phoneExtn" size="10" title="Please enter your phone extension" /></span>
    </div>
    <div>
        <span><strong>City:</strong></span> <span>
            <input type="text" id="city" name="city" size="25" title="Please enter your city" /></span>
        <span><strong>State:</strong></span> <span>
            <select id="country" name="country" title="Please select your state from the drop down list">
                <option selected="" value="Default">Select a State</option>
                <option value="AL">Alabama</option>
                <option value="AK">Alaska</option>
                <option value="AZ">Arizona</option>
                <option value="AR">Arkansas</option>
                <option value="CA">California</option>
                <option value="CO">Colorado</option>
                <option value="CT">Connecticut</option>
                <option value="DE">Delaware</option>
                <option value="DC">District of Columbia</option>
                <option value="FL">Florida</option>
                <option value="GA">Georgia</option>
                <option value="GU">Guam</option>
                <option value="HI">Hawaii</option>
                <option value="ID">Idaho</option>
                <option value="IL">Illinois</option>
                <option value="IN">Indiana</option>
                <option value="IA">Iowa</option>
                <option value="KS">Kansas</option>
                <option value="KY">Kentucky</option>
                <option value="LA">Louisiana</option>
                <option value="ME">Maine</option>
                <option value="MD">Maryland</option>
                <option value="MA">Massachusetts</option>
                <option value="MI">Michigan</option>
                <option value="MN">Minnesota</option>
                <option value="MS">Mississippi</option>
                <option value="MO">Missouri</option>
                <option value="MT">Montana</option>
                <option value="NE">Nebraska</option>
                <option value="NV">Nevada</option>
                <option value="NH">New Hampshire</option>
                <option value="NJ">New Jersey</option>
                <option value="NM">New Mexico</option>
                <option value="NY">New York</option>
                <option value="NC">North Carolina</option>
                <option value="ND">North Dakota</option>
                <option value="OH">Ohio</option>
                <option value="OK">Oklahoma</option>
                <option value="OR">Oregon</option>
                <option value="PA">Pennsylvania</option>
                <option value="PR">Puerto Rico</option>
                <option value="RI">Rhode Island</option>
                <option value="SC">South Carolina</option>
                <option value="SD">South Dokota</option>
                <option value="TN">Tennessee</option>
                <option value="TX">Texas</option>
                <option value="UT">Utah</option>
                <option value="VT">Vermont</option>
                <option value="VI">Virgin Islands</option>
                <option value="VA">Virginia</option>
                <option value="WA">Washington</option>
                <option value="WV">West Virginia</option>
                <option value="WI">Wisconsin</option>
                <option value="WY">Wyoming</option>
            </select></span>
    </div>
    <div>
        <span><strong>Zip Code:</strong></span> <span>
            <input type="text" id="zip" name="zip" size="10" title="Please enter your zip code" /></span>
    </div>
    <br />
    <div id="qsadditionalRequirementsQuestion">
        <strong>Briefly describe your purpose for contacting us today:</strong>
    </div>
    <div>
        <textarea name="PurposeForContact" rows="5" cols="60"></textarea>
    </div>
    <div>
        <input type="submit" name="submit" value="Submit" />
    </div>
    </form>
  • 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-19T01:41:01+00:00Added an answer on June 19, 2026 at 1:41 am

    Your main if statements are contained within random opening and closing braces.

    Try removing those random braces, adding return true; inside of your last nested if statement, and containing the return false; within an elseif after the closing braces of the if statements

    EDIT:

    if (allLetter(uname)) {
        if (alphanumeric(uadd)) {
           if (countryselect(ucountry)) {
            if (allnumeric(uzip)) {
                if (ValidateEmail(uemail)) {
                    if (validatePhone(uphone)) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }
                else {
                    return false;
                }
            }
            else {
                return false;
            }
        }
        else {
            return false;
        }
    }
    else {
        return false;
    }
    }
    else {
    return false;
    }
    

    There are much, much better ways of doing this, but without changing what you’ve already got too much, try the above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.