Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Contact Search Form
<?php
/**
* To build a search form, extend the BackendExtendedSearchForm
*
* Then, just add some more elements into it, like in the example below.
* When you add the elements, don't forget to render them in the view, and
* fetch them in the controller when the form is submitted.
*
* You can also write a form manually, but make sure you give it the class
* backendExtendedSearchForm
* because it needs to automatically fetch the global search Q value.
*
* Never include a textual Q search in the search form.
*/
namespace Manager\Form;
use Manager\Form\Abstracts\BackendExtendedSearchForm;
class ContactSearch extends BackendExtendedSearchForm
{
public function __construct($name = null)
{
// GIVE YOUR FORM A NAME
parent::__construct('contactsearchform');
// GIVE YOUR SUBMIT BUTTON A LABEL [optional]
$this->setSubmitLabel('Search Contacts');
// ADD CLASS FOR EASIER STYLING
$this->addClass('contactSearchForm');
// ADDING SEARCH ELEMENTS ==============================
$oValiditySelector = new \Application\Form\FormHelpers\ContactValidityDropdown('validity');
$oValiditySelector->setLabel('');
$this->add($oValiditySelector);
// =====================================================
$oDeleteSelector = new \Zend\Form\Element\Select('deleted');
$oDeleteSelector->setValueOptions(array(
array('value' => '0', 'label' => 'Not Deleted', 'selected' => true),
array('value' => '', 'label' => 'Both'),
array('value' => '1', 'label' => 'Deleted')
));
$this->add($oDeleteSelector);
$oActivated = new \Zend\Form\Element\Select('activated');
$oActivated->setValueOptions(array(
array('value' => '', 'label' => 'Act. + Non Act.', 'selected' => true),
array('value' => '0', 'label' => 'Not Activated'),
array('value' => '1', 'label' => 'Activated')
));
$this->add($oActivated);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment