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

  • Home
  • SEARCH
  • 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 6372295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:13:07+00:00 2026-05-25T01:13:07+00:00

I’m using this construction for my element: $freetext = $this->CreateElement(‘textarea’, ‘freetext’) ->setLabel(‘Comments’) ->setAttrib(‘class’,’input-textarea’) ->setOptions(array(‘rows’

  • 0

I’m using this construction for my element:

$freetext = $this->CreateElement('textarea', 'freetext')
            ->setLabel('Comments')
            ->setAttrib('class','input-textarea')
            ->setOptions(array('rows' => '2', 'cols'=>'30'))
            ->addValidator('StringLength', false, array(0,500))
            ->addFilter('HtmlEntities')
            ->addFilter('StripTags')
            ->setRequired(true);

I want to add an “allowEmpty” to this but can’t find the correct syntax. I was hoping for something like:

...    ->addValidator('allowEmpty', false, true)

But this does not work.

Edit: I’ve changed the setRequired() to true – I want to allow empty string as an acceptable value on a require field.

Regardless of usage, how do I add this option to my element?

  • 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-05-25T01:13:08+00:00Added an answer on May 25, 2026 at 1:13 am
    $freetext = $this->CreateElement('textarea', 'freetext')
                ->addValidator('StringLength', false, array(10,500))
                ->setRequired(false);
    

    Your code should already do that, the setRequired(false) method do what you’re asking for, i.e. if the value is not submitted then validators won’t be run.

    Do you have any issue with the code you’ve written, some validation error messages or something else?

    Update

    I’ve changed the setRequired() to true – I want to allow empty string as an acceptable value on a require field.

    What is the semantic in setRequired(true) and allowing the empty string as a valid value? Or better what do you require if the element can be empty?

    What you’ve asked in the edit is a no sense, because if an element is required it MUST have a value different from the empty string. If you need to accept the empty string as a valid value just use setRequired(false). When you get form values with Zend_Form::getValues() or Zend_Form_Element::getValue() you’ll obtain the empty string as result.

    Anyway here it’s the explanation of setRequired and setAllowEmpty from ZF manual:

    Using the defaults, validating an Element without passing a value, or
    passing an empty string for it, skips all validators and validates to
    TRUE.

    • setAllowEmpty(false) leaving the two other mentioned flags
      untouched, will validate against the validator chain you defined for
      this Element, regardless of the value passed to isValid().

    • setRequired(true) leaving the two other mentioned flags untouched,
      will add a ‘NotEmpty’ validator on top of the validator chain (if none
      was already set)), with the $breakChainOnFailure flag set. This
      behavior lends required flag semantic meaning: if no value is passed,
      we immediately invalidate the submission and notify the user, and
      prevent other validators from running on what we already know is
      invalid data.

    If you do not want this behavior, you can turn it off by passing a
    FALSE value to setAutoInsertNotEmptyValidator($flag); this will
    prevent isValid() from placing the ‘NotEmpty’ validator in the
    validator chain.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.