addElement('text', 'name', array('label' => 'School Name', 'required' => true)); $form->addElement('extendedImage', 'logo', array('label' => 'Logo image', 'resize' => '200x80')); $form->addElement('text', 'location', array('label' => 'Location (City, State)', 'required' => true)); $form->addElement('text', 'grades', array('label' => 'Grades', 'required' => true)); $form->addElement('text', 'url', array('label' => 'URL', 'description' => 'Example: http://www.google.com')); $form->url->addValidator('Regex', true, array('/^http(s)?:\/\/.+/')); $form->url->getValidator('Regex')->setMessage( 'Url is in wrong format', Zend_Validate_Regex::NOT_MATCH ); $form->addElement( 'checkbox', 'enabled', array('label' => 'Show on userend Authorized Schools page?', 'description' => 'Image / Location / Grades required to show', 'checked' => 'y', 'checkedValue' => 'y', 'uncheckedValue' => 'n') ); $form->enabled->getDecorator('Description')->setTag('span'); $form->addFormRule(array($this, 'validateForm')); return $this; } public function validateForm($data) { $errors = array(); if ($data['enabled'] == 'y') { if (!empty($_FILES)) { $logoError = 'Logo is required'; if ($this->dataObj->getPrimaryKey()) { $image = $this->dataObj->getImage(); if (empty($image)) { if (!is_uploaded_file($_FILES['logo']['tmp_name'])) { $errors['logo'] = $logoError; } } } else { if (!is_uploaded_file($_FILES['logo']['tmp_name'])) { $errors['logo'] = $logoError; } } } } return (empty($errors)) ? true : $errors; } protected function _bindListColumns($list) { $list->addColumn('no', 'sorter', array('orderBy' => 'sorter')); $list->addColumn('text', 'name', array('title' => 'Name', 'orderBy' => 'name')); $list->addColumn('contacts', 'contacts', array('title' => 'Contacts')); $list->addColumn( 'show', 'enabled', array('title' => 'Show', 'orderBy' => 'enabled', 'url' => BASE_URL . '/' . CURRENT_PAGE . '?action=changeOption&', 'values' => array('y' => 'Yes', 'n' => 'No'), 'key' => array('id')) ); $list->addColumn('options', 'options'); return $this; } }