public function getAddEditForm($target = '/admin/Campaigns§ion=addedit') { $form = new Form('campaign_addedit', 'POST', $target, '', array('class' => 'admin', 'onsubmit' => 'disableSubmit(this);')); $form->addElement('text', 'name', 'Name'); $form->addElement('select', 'auto_send', 'Auto-reminder on start', array(0 => 'Disable', 1 => 'Enable')); $date[] = $form->createElement('date', 'start_date', 'Start Date', array('format' => 'd F Y - H : i', 'addEmptyOption' => 'true', 'emptyOptionValue' => '', 'emptyOptionText' => 'Select', 'minYear' => date('Y'), 'maxYear' => date('Y') + 3), array('onchange' => 'return !updateEndDate(this)')); $date[] = $form->createElement('date', 'end_date', 'End Date', array('format' => 'd F Y - H : i', 'addEmptyOption' => 'true', 'emptyOptionValue' => '', 'emptyOptionText' => 'Select', 'minYear' => date('Y'), 'maxYear' => date('Y') + 5)); $form->addElement($date[0]); $form->addElement($date[1]); $form->addElement('tinymce', 'description', 'Description'); $form->addElement('submit', 'submit', 'Submit'); if (!is_null($this->id)) { $form->setConstants(array('campaign_id' => $this->getId())); $form->addElement('hidden', 'campaign_id'); $defaultValues['name'] = $this->getName(); $defaultValues['start_date'] = $this->getStartDate(); $defaultValues['end_date'] = $this->getEndDate(); $defaultValues['description'] = $this->getDescription(); $defaultValues['auto_send'] = $this->getAutoSend(); $form->setDefaults($defaultValues); } $form->registerRule('validDate', 'function', 'validDates', $this); //ValidDate... get it? $form->addRule(array('start_date', 'end_date'), 'Please make sure that the event has a positive length and that it begins after the current date/time', 'validDate'); $form->addRule('name', 'Please enter a campaign name', 'required'); if ($form->isSubmitted() && isset($_POST['submit'])) { if ($form->validate()) { $this->setName($form->exportValue('name')); $this->setGroup($_SESSION['authenticated_user']->getAuthGroup()); $this->setDescription($form->exportValue('description')); $this->setStartDate($this->formatDate($form->exportValue('start_date'))); $this->setEndDate($this->formatDate($form->exportValue('end_date'))); $this->setStatus($this->calcStatus()); $this->setAutoSend($form->exportValue('auto_send')); $this->save(); } } return $form; }