Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZF2: How to set form elements to be ignored?

Somehow I can't get Form Elements in Zend Framework 2 to be ignored.

All of this doesn't seem to work:

$this->add(array(
  'name' => 'submit',
  'ignore' => TRUE,
  'attributes' => array(
    'type'  => 'submit',
    'value' => 'Go!',
    'id' => 'submitbutton',
    'ignore' => TRUE
),
'options' => array(
  'ignore' => TRUE
)
));

This is how it used to work in Zend Framework1:

//Zend Framework 1
$this->addElement(
  'submit',
  'login',
  array(
   'ignore' => true,
   'label' => 'Login'
    )
);

EDIT:
Why would I need the option "ignore"?

Let's say your form has a submit button. With normal PHP, something like $_POST will also list your submit button. Zend 1 has the useful options setIgnore($flag) and getIgnore() to exclude such elements. $form->getValues() (after validation) would exclude all elements with flag 'ignore' set to TRUE. See ZF1 manual.

like image 454
mdthh Avatar asked Nov 03 '22 01:11

mdthh


1 Answers

Check out about inputfilters

My use is like that:

  1. create your form
  2. create a filter
  3. in controller use that

    $form = new BasicForm();
    $form->setInputFilter(new BasicFilter());
    

About the filter, you can do this: $factory = new InputFactory();

    $this->add($factory->createInput(array(
        'name' => 'birthday',
        'required' => false,
        'allowEmpty' => true,));
like image 168
Remi Thomas Avatar answered Nov 15 '22 12:11

Remi Thomas