# Form Elements Shipped With Icinga 2 Web On top of the elements provided by the Zend Framework, Icinga 2 Web ships its own to offer additional functionality. The following is a list of these classes, as well as descriptions of the functionality they offer. ## Elements ### DateTimePicker `Icinga\Web\Form\Element\DateTimePicker` represents a control that allows the user to select date/time and to display the date and time with a user specified format. Internally the element returns the input as Unix timestamp after it has been proven valid. That is when the input is valid to `\DateTime::createFromFormat()` according to the user specified format. Input is always timezone aware because the element utilizes `Icinga\Util\DateTimeFactory` which relies on the timezone set by the user. **Example #1 DateTimePicker expecting date** use Icinga\Web\Form\Element\DateTimePicker; $element = new DateTimePicker( array( 'name' => 'date', 'label' => t('Date'), 'patterns' => array('Y-m-d') // Allowed format ) ) **Example #2 DateTimePicker expecting time** use Icinga\Web\Form\Element\DateTimePicker; $element = new DateTimePicker( array( 'name' => 'time', 'label' => t('Time'), 'patterns' => array('H:i:s') // Allowed format ) ) **Example #3 DateTimePicker expecting date and time** use Icinga\Web\Form\Element\DateTimePicker; $element = new DateTimePicker( array( 'name' => 'datetime', 'label' => t('Date And Time'), 'patterns' => array('Y-m-d H:i:s') // Allowed format ) ) **Example #4 DateTimePicker expecting date/time w/ default value** use Icinga\Web\Form\Element\DateTimePicker; use Icinga\Util\DateTimeFactory; $now = DateTimeFactory::create(); $element = new DateTimePicker( array( 'name' => 'datetime', 'label' => t('Date/Time'), 'value' => $now->getTimestamp() + 3600, // now plus 1 hour 'patterns' => array('Y-m-d H:i:s', 'Y-m-d', 'H:i:s') // Allowed format ) ) ## Validators ### WritablePathValidator This *Icinga\Web\Form\Validator\WritablePathValidator* validator tests a given (string-)input for being a valid writable path. Normally it just tests for an existing, writable path but when setRequireExistence() is called, the path must exist on form submission and be writable. **Example usage of writablePathValidator use \Icinga\Web\Form\Validator\WritablePathValidator; $txtLogPath = new Zend_Form_Element_Text( array( 'name' => 'logging_app_target', 'label' => 'Application Log Path', 'helptext' => 'The logfile to write the icingaweb debug logs to.' . 'The webserver must be able to write at this location', 'required' => true, 'value' => $logging->get('target', '/var/log/icingaweb.log') ) ); $txtLogPath->addValidator(new WritablePathValidator()); ### DateTimeValidator The *Icinga\Web\Form\Validator\DateTimeValidator* validator allows you to validate an input against a set of datetime patterns. On successful validation, it either gives a valid pattern via getValidPattern, or null if the entered time is a timestamp. The above DateTimePicker utilizes this validator and should be used instead of directly using the validator. ## Decorators ### ConditionalHidden Decorator The `Icinga\Web\Form\Decorator\ConditionalHidden` allows you to hide a form element with the 'conditional' attribute for users that don't have JavaScript enabled (the form is rendered in a \