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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:23:01+00:00 2026-06-08T22:23:01+00:00

I have looked at other questions /Googled this. My problem is that when I

  • 0

I have looked at other questions/Googled this. My problem is that when I submit my form with empty textboxes that have a notEmpty validator, it triggers no error.

First, I would like to see if I understand the difference between notEmpty and setRequired. As I understand, the notEmpty validator gives an error if an element is submitted and the value is empty. That is, if an entry does not exist in the POST data (for forms), then it does not generate an error if the element is not required. Like it only runs if the element is set. The setRequired method will automatically add a notEmpty validator behind the scenes unless told otherwise. This ensures that an entry for an element must exist and it must not be empty. Correct?

Now, I tried to use this logic in my form where I added notEmpty validators, like so:

$username = new Zend_Form_Element_Text('txtUsername');
$username->addValidator(new Zend_Validate_NotEmpty(), true);

And the same for other text fields. If I submit my form without entering a value, my POST data looks like this:

(
    [txtUsername] => 
    [txtPassword] => 
    [txtRepeatPassword] => 
)

However, isValid still evaluates to true and no error messages are generated. Why? Shouldn’t the notEmpty validator determine that the values are empty since the element has an entry in the POST data? If I use setRequired(true), it works how I want. It just messes with my mind that it determines that the username is not empty when the value is an empty string. 🙂

Thanks in advance.

  • 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-08T22:23:04+00:00Added an answer on June 8, 2026 at 10:23 pm

    I agree that this is a little confusing. The reason is that all form elements have an allowEmpty flag (true by default), that skips validation if the value is blank. It works this way because otherwise, adding validators to optional elements would be a real pain, e.g.:

    $dateOfBirth = new Zend_Form_Element_Text('dob');
    $dateOfBirth->setLabel('Date of birth (optional)');
    $dateOfBirth->addValidator(new Zend_Validate_Date());
    $form->addElement($dateOfBirth);
    

    this would always fail validation if the user chose not to enter their DOB, as ” is not a valid date. With the allowEmpty flag on by default it works as you would expect (it only validates the date when one has been entered).

    Calling setRequired(true) adds a NotEmpty validator but it also sets the allowEmpty flag to false. I would recommend you stick with this approach. Alternatively you can get your way to work by setting the flag as well:

    $username = new Zend_Form_Element_Text('txtUsername');
    $username->addValidator(new Zend_Validate_NotEmpty());
    $username->setAllowEmpty(false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked at other questions regarding this problem but the solutions don't work
Just to make this clear, I have looked at the other questions on this
I have looked at other questions on this and so far I haven't been
I have looked at the other questions on here about this. It isn't working.
I have looked at other questions and answers regarding this, but can't seem to
I have looked over other questions on this website, but am yet to find
I would like to mention before continuing that I have looked at other questions
I have looked at other questions and cannot find the answer to why this
I looked at other questions regarding this problem and tried their solutions, but it
I have looked for similar questions, but could find none other than the difference

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.