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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:43:57+00:00 2026-06-08T04:43:57+00:00

I have a form which consists of selects/dropdowns. I have set their default values

  • 0

I have a form which consists of selects/dropdowns. I have set their default values to be -1. When the form is submitted, I want to validate that the submitted value is not equal to the default value. I tried setRequired(true), but as far as I know, that is just a convenient way of adding a notEmpty validator, which is not really what I want.

Here is a part of my form:

    $select = new Zend_Form_Element_Select('myselect');
    $select->setMultiOptions(array(
                        '-1' => 'Gender',
                        '0' => 'Female',
                        '1' => 'Male'
                    ))
                    ->addValidator(new Zend_Validate_Int(), false);

    $this->setDefaults(array('myselect' => -1));

And here is my controller:

if ($this->getRequest()->isPost()) {
            $form = new My_Form_Contact();

            if ($form->isValidPartial(array('myselect' => $this->getRequest()->getPost('myselect')))) {
                // "myselect" is valid
            }

I need to use the isValidPartial method because I need to use different logic depending on which elements have a value that is different from their default value. I guess what I need is a notEqual validator, but I couldn’t find one. I know that it is possible to make my own validators, but I wanted to ask if there is an easier way first. I also looked at Zend_Validate_Identical, but I don’t think I can make use of it in this case.

To sum up: I only want my select to be validated successfully if the submitted value is not equal to the default value.

  • 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-08T04:43:59+00:00Added an answer on June 8, 2026 at 4:43 am

    The simplest solution is to use an empty string as the default:

    $select->setMultiOptions(array(
                        '' => 'Gender',
                        '0' => 'Female',
                        '1' => 'Male'
                    ))
                    ->addValidator(new Zend_Validate_Int(), false)
                    ->addValidator(new Zend_Validate_NotEmpty(), false);
    
    $this->setDefaults(array('myselect' => ''));
    

    but I’m guessing you already thought of that, and discounted it from some reason.

    So, the next easiest is to use GreaterThan():

    $select->setMultiOptions(array(
                        '-1' => 'Gender',
                        '0' => 'Female',
                        '1' => 'Male'
                    ))
                    ->addValidator(new Zend_Validate_Int(), false)
                    ->addValidator(new Zend_Validate_GreaterThan(-1), false);
    
    $this->setDefaults(array('myselect' => '-1'));
    

    I hope that is what you are looking for.

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

Sidebar

Related Questions

I have a facebook application that consists of a form which values i want
I have a form which consists of 2 steps. What I'd like to do
I have a form which I want to be 'resusable' for a variety of
I have a simple HTML form which consists of radio buttons where user has
I have a very simple web form which consists of labels and input fields,
I have a pretty large form that consists of radio buttons/checkboxes as well as
I have an HTML form which consists of several fieldsets (each has identical fields).
I have a c# .net 2.0 winforms application which consists basically of one form
I have a JSF page that is basically a create form. The form consists
I have a form that consists of: 3 text boxes (first two are required

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.