예제 #1
0
 public function getForm()
 {
     $form = new Stuffpress_Form();
     // Add the form element details
     $form->setMethod('post');
     $form->setName("form_page");
     // Create and configure title element:
     $e = $form->createElement('text', 'title', array('label' => 'Title:', 'class' => 'width1'));
     $e->setRequired(true);
     $e->addValidator('stringLength', false, array(0, 32));
     $e->addFilter('StripTags');
     $form->addElement($e);
     // Create and configure title element:
     $e = $form->createElement('text', 'url', array('label' => 'Url:', 'class' => 'width1'));
     $e->setRequired(true);
     $e->addValidator('stringLength', false, array(0, 128));
     $e->addFilter('StripTags');
     $form->addElement($e);
     // Add a hidden element with the page id
     $e = $form->createElement('hidden', 'id');
     $e->removeDecorator('HtmlTag');
     $form->addElement($e);
     // Add a hidden element with the  page type
     $e = $form->createElement('hidden', 'type');
     $e->setValue('link');
     $e->removeDecorator('HtmlTag');
     $form->addElement($e);
     // Add a submit button
     $button = $form->createElement('submit', 'save', array('onClick' => 'onFormSubmit(); return false;', 'decorators' => array('ViewHelper')));
     $form->addElement($button);
     // Add a cancel button
     $element = $form->createElement('button', 'cancel', array('decorators' => array('ViewHelper')));
     $element->setAttrib('onClick', 'history.go(-1);return false;');
     $form->addElement($element);
     // Group elements
     $form->addDisplayGroup(array('save', 'cancel'), 'buttons', array('decorators' => $form->groupDecorators));
     return $form;
 }
예제 #2
0
 private function getForm($source_id = 0, $item_id = 0)
 {
     $form = new Stuffpress_Form();
     // Add the form element details
     $form->setMethod('post');
     $form->setName("form_add_comment_{$source_id}_{$item_id}");
     // Create and configure comment element:
     $comment = $form->createElement('textarea', 'comment', array('label' => 'Comment:', 'rows' => 4, 'cols' => 60, 'decorators' => $form->elementDecorators));
     $comment->setRequired(true);
     $comment->addFilter('StripTags');
     if ($this->_application->user) {
         $name = $form->createElement('hidden', 'name');
         $name->setValue($this->_application->user->username);
         $name->setDecorators(array(array('ViewHelper')));
         $email = $form->createElement('hidden', 'email');
         $email->setValue($this->_application->user->email);
         $email->setDecorators(array(array('ViewHelper')));
         $config = Zend_Registry::get('configuration');
         $host = $config->web->host;
         $url = $this->_application->getPublicDomain();
         $website = $form->createElement('hidden', 'website');
         $website->setValue($url);
         $website->setDecorators(array(array('ViewHelper')));
         $website->addFilter('StripTags');
     } else {
         // Create and configure username element:
         $name = $form->createElement('text', 'name', array('label' => 'Name:', 'decorators' => $form->elementDecorators));
         $name->addFilter('StringToLower');
         $name->addValidator('alnum');
         $name->addValidator('stringLength', false, array(4, 20));
         $name->setRequired(true);
         // Create and configure email element:
         $email = $form->createElement('text', 'email', array('label' => 'Email (confidential):', 'decorators' => $form->elementDecorators));
         $email->addValidator(new Zend_Validate_EmailAddress());
         $email->setRequired(true);
         // Create and configure website element:
         // TODO Add URL validator
         $website = $form->createElement('text', 'website', array('label' => 'Website (optional):', 'decorators' => $form->elementDecorators));
         $website->addFilter('StripTags');
         $website->setRequired(false);
     }
     $options = new Zend_Form_Element_MultiCheckbox('options', array('decorators' => $form->elementDecorators, 'multiOptions' => array('notify' => 'Notify me of followup comments via e-mail')));
     $options->setValue(array('notify'));
     // Add elements to form:
     $form->addElement($comment);
     $form->addElement($name);
     $form->addElement($email);
     $form->addElement($website);
     $form->addElement($options);
     // Add a hidden element with the source id
     $element = $form->createElement('hidden', 'source');
     $element->setValue($source_id);
     $element->setDecorators(array(array('ViewHelper')));
     $form->addElement($element);
     // Add a hidden element with the item id
     $element = $form->createElement('hidden', 'item');
     $element->setValue($item_id);
     $element->setDecorators(array(array('ViewHelper')));
     $form->addElement($element);
     // Post button
     $button = $form->createElement('button', 'post', array('label' => 'Post', 'onclick' => "submitFormAddComment({$source_id}, {$item_id});", 'decorators' => array('ViewHelper')));
     $button->setDecorators(array(array('ViewHelper')));
     $form->addElement($button);
     // Cancel button
     $button = $form->createElement('button', 'cancel', array('label' => 'Cancel', 'onclick' => "cancelFormAddComment({$source_id}, {$item_id});", 'decorators' => array('ViewHelper')));
     $button->setDecorators(array(array('ViewHelper')));
     $form->addElement($button);
     $form->addDisplayGroup(array('post', 'cancel'), 'buttons', array('decorators' => $form->groupDecorators));
     return $form;
 }