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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:11:56+00:00 2026-06-05T05:11:56+00:00

I’m creating a form with the Zend Framework to capture user demographics. I’m struggling

  • 0

I’m creating a form with the Zend Framework to capture user demographics. I’m struggling with validation for digits on two text fields.

I build my form in ../application/forms/UserDemographics.php like this:

class Application_Form_UserDemographics extends Zend_Form
    {
        public function init()
        {
            $this->form = new Zend_Form;            
            $dbAdapter = Zend_Registry::get("db");  

                        ...

                        $this->fax_number = new Zend_Form_Element_Text('fax_number');
            $this->fax_number->setLabel('Fax Number')
                ->addFilter('Int')
                ->addFilter('StripTags')
                ->addValidator('Digits');   

                        $this->mobile_number = new Zend_Form_Element_Text('mobile_number');
            $this->mobile_number->setLabel('Mobile Number')
                ->addFilter('Int')
                ->addFilter('StripTags')
                ->addValidator('Digits');

                        ...

                }
         }

My database is currently configured like this with regards to the fax_number and mobile_number fields so that I could test whether or not digits are accepted or not:

+-----------------+-------------+------+-----+---------+----------------+
| Field           | Type        | Null | Key | Default | Extra          |
+-----------------+-------------+------+-----+---------+----------------+
...
| fax_number      | varchar(32) | NO   |     | NULL    |              
| mobile_number   | int(15)     | YES  |     | NULL    |              
...

When I enter anything but digits in either one of the fields in the zend form – no error message is displayed even though I have a validator for digits added to both of the elements.

The text entered into the mobile number text field is replace by a 0 (zero) in the database:

mysql> select fax_number, mobile_number from user_demographics;
+--------------------+---------------+
| fax_number         | mobile_number |
+--------------------+---------------+
| var char no digits |             0 |
+--------------------+---------------+

At the very least the mobile_number field should show an error message saying that only digits can be entered into the text field, right?

And why does it seem that the Digits validator is not recognised?

This basically shows that the Digits validator is almost ignored. The text fields have 0’s (zeros) in them when the form is rendered but no error messages are displayed when I enter text into the text field – not even for the mobile_number field that is set to be int in the database.

Please advise?

  • 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-05T05:11:57+00:00Added an answer on June 5, 2026 at 5:11 am

    This is because the filters are processed before the validators.

    So what your code does is the following:

    1. Take the Input
    2. Convert it to int, which will be 0 in case any non-convertable text is contained
    3. Strip the tags
    4. Check if the input contains only digits, which will always be the case because of the int-filter.

    So to work around this, simply remove the int-filter:

    class Application_Form_UserDemographics extends Zend_Form
    {
        public function init()
        {
            $this->form = new Zend_Form;            
            $dbAdapter = Zend_Registry::get("db");  
    
                        ...
    
                        $this->fax_number = new Zend_Form_Element_Text('fax_number');
            $this->fax_number->setLabel('Fax Number')
                ->addFilter('StripTags')
                ->addValidator('Digits');   
    
                        $this->mobile_number = new Zend_Form_Element_Text('mobile_number');
            $this->mobile_number->setLabel('Mobile Number')
                ->addFilter('StripTags')
                ->addValidator('Digits');
    
                        ...
    
                }
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
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
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.