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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:10:49+00:00 2026-06-17T10:10:49+00:00

I am trying to create a single abstract class to manage input validation –

  • 0

I am trying to create a single abstract class to manage input validation – in this class I have static functions that return InputFilterInterface objects that I can then add to my interface in the model class that handles the data. However, none of the data ever seems to be validated even though it is valid. I am not using Forms, by the way – the data is coming in via Ajax rather than an HTML form.

Here is my code:

Central Library:

abastract class InputFilters {
    public static function monthIDFilter($fieldName = 'monthID', $required = FALSE) {
        $factory = new InputFactory();
        return $factory->createInputFilter(array(
            $fieldName => array(
                'name' => $fieldName,
                'required' => $required,
                'validators' => array(
                    array('name' => 'not_empty'),
                    array('name' => 'string_length', 'options' => array(
                        'min'=>'6', 'max'=>'6'
                    )),
                    array('name' => 'regex', 'options'=>array(
                        'pattern' => '/^[0-9]{6}$/'
                    ))
                ),
            )
        ));
    }
}

Model:

class DataModel implements \Zend\InputFilter\InputFilterAwareInterface {
    protected $_inputFilter;

    public function __construct()
    {
        $this->setInputFilter(InputFilters::monthIDFilter());
    }

    public function setInputFilter(InputFilterInterface $inputfilter)
    {
        if(!$this->_inputFilter) {
            $this->_inputFilter = new InputFilter();
        }
        $this->_inputFilter->add($inputfilter);
    }

    public function getInputFilter()
    {
        if(!$this->_inputFilter) {
            $this->_inputFilter = new InputFilter();
        }
        return $this->_inputFilter;
    }
}

And finally, in the controller:

public function dataAction()
{
    $model = new DataModel();
    $inputFilter = $model->getInputFilter();
    $inputFilter->setData($_REQUEST);
    print_r($_REQUEST);
    print_r($inputFilter->getValues());
    if ($inputFilter->isValid()) {
        if ($inputFilter->has('monthID')) {
            echo $inputFilter->getValue('monthID');
            $formMonth = $inputFilter->getValue('monthID');
        } else {
            echo 'nope';
            $formMonth = '';
        }
        $grid->setSqlString($formMonth);
        $data = $grid->outputData();
        Json::out($data);
    }

In my output, I see the input that contains my monthID (201212) and an array that should be the validation results: Array ( [] => Array ( [monthID] => ) ) and the word ‘nope’ indicating that the has(‘monthID’) check failed.

Any advice as to where I went wrong?

  • 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-17T10:10:50+00:00Added an answer on June 17, 2026 at 10:10 am

    Try Changing createInputFilter to createInput inside your DataModel.

        return $factory->createInput(array(
            $fieldName => array(
                'name' => $fieldName,
                'required' => $required,
                'validators' => array(
                    array('name' => 'not_empty'),
                    array('name' => 'string_length', 'options' => array(
                        'min'=>'6', 'max'=>'6'
                    )),
                    array('name' => 'regex', 'options'=>array(
                        'pattern' => '/^[0-9]{6}$/'
                    ))
                ),
            )
        ));
    
    • 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 a single 'query' NSString object that basically looks like this:
I am trying to create buttons that play single sound files and one button
I am trying to create a single sign on process. The method I have
I am trying to create a single array that contains all of the values
I am trying to create a single link (inside a snippit) that will link
I am trying to create a single-choice (e.g., radio button) list of items that
I'm trying to create a single class which will deal with storing and retrieving
I'm trying to create a single query that will combine the following two queries.
I am trying to create a single query that will pull results from a
I am trying to create a single web page that will display easily on

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.