zendframework/zf2 — pull request #2170 by odnanref (2012-08-14 23:04:40+00:00)
Title: Wasn't able to insert data properly in the Db after using inputFilter

* InputFilter setting primaryKey to zero value so I couldn't test this for null or filter set's it to empty string
* For Updating Basically you will need to populate the object with data before placing the
changes from the "form" and then you can execute save() for the Db update.
* Only needs to populate the originalData on Row Change

My filter:
```PHP
$inputFilter = new InputFilter();
$factory = new InputFactory();

$inputFilter->add($inpt = $factory->createInput(array(
'name' => 'idsupplier',
'required' => false,
'filters' => array(
array('name' => 'Int'),
),
)));

$inputFilter->add($factory->createInput(array(
'name' => 'name',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 254,
),
),
),
)));

$inputFilter->add($factory->createInput(array(
'name' => 'company',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 254,
),
),
),
)));

$inputFilter->add($factory->createInput(array(
'name' => 'idsuppliertype',
'required' => true,
'filters' => array(
array('name' => 'Int'),
),
)));
```

*Example add*

```PHP
public function addAction()
{
$form = new SupplierForm($this->getSupplierTypes());
$form->get('submit')->setValue('Add');

$request = $this->getRequest();
if ($request->isPost()) {
$supplier = new Supplier($this->getSupplierTable()->getAdapter());
$form->setInputFilter($supplier->getInputFilter());
$form->setData($request->getPost());

if ($form->isValid()) {
$supplier->populate($form->getData());
$id = $supplier->save();

// Redirect to list of albums
return $this->redirect()->toRoute('supplier/list');
}
}
return array('form' => $form);
}
```
*Example Edit*
```PHP
public function editAction()
{
$id = (int) $this->params()->fromRoute('id', 0);
if (!$id) {
return $this->redirect()->toRoute('supplier', array(
'action' => 'add'
));
}
$supplierRow = $this->getSupplierTable()->fetchRow("idsupplier = " . (int) $id);
$supplier = new Supplier($this->getSupplierTable()->getAdapter());

$supplier->populate((array)$supplierRow);

$form = new SupplierForm($this->getSupplierTypes());
$form->bind($supplierRow);
$form->get('submit')->setAttribute('value', 'Edit');

$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
$form->setInputFilter($supplier->getInputFilter());
if ($form->isValid()) {
$supplier->exchangeArray((array)$supplierRow);
$supplier->save();

// Redirect to list of albums
return $this->redirect()->toRoute('supplier');
}
}

return array(
'id' => $id,
'form' => $form,
);
}
```

**This was based on akrabat code with changes to reduce my work.**