/** * Gets the form for adding and editing a document * * @param array $values * @return Zend_Form */ public function form($values = array()) { $config = Zend_Registry::get('config'); $form = new Zend_Form(); $form->setAttrib('id', 'documentForm')->setAttrib('enctype', 'multipart/form-data')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $file = $form->createElement('file', 'document', array('label' => 'Upload File:')); $file->setRequired(true)->addValidator('Count', false, 1)->addValidator('Size', false, 10240000)->addValidator('Extension', false, $config->user->fileUploadAllowableExtensions->val ? $config->user->fileUploadAllowableExtensions->val : ""); if (!isset($values['workshopDocumentId'])) { $form->addElement($file); } $title = $form->createElement('text', 'description', array('label' => 'File Description:')); $title->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '255')->setValue(isset($values['description']) ? $values['description'] : ''); $form->addElement($title); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); $file->setDecorators(array('File', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span')))); if (isset($values['workshopDocumentId'])) { $workshopDocumentId = $form->createElement('hidden', 'workshopDocumentId'); $workshopDocumentId->setValue($values['workshopDocumentId']); $workshopDocumentId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($workshopDocumentId); } return $form; }
public function getAddContentForm($submitLabel, $contentTitle = null, $contentDescription = null) { $database = Zend_Db_Table::getDefaultAdapter(); $content = $database->select()->from('content')->order('content_id DESC')->query()->fetch(); $imageName = $content['content_id'] + 1; $form = new Zend_Form(); $form->setMethod('post'); if ($submitLabel == 'Add Content!') { $form->setAttrib('enctype', 'multipart/form-data'); $image = new Zend_Form_Element_File('foo'); $image->setLabel('Upload an image:')->setDestination('../images'); $image->addFilter('Rename', array('target' => $imageName . '.jpg', 'overwrite' => TRUE)); $image->addValidator('Count', false, 1); $image->addValidator('Extension', false, 'jpg,png,gif'); $form->addElement($image, 'foo'); } $title = $form->createElement('text', 'title'); $title->setRequired(true); $title->setValue($contentTitle); $title->setLabel('Title'); $form->addElement($title); $description = $form->createElement('textarea', 'description', array('rows' => 10)); $description->setRequired(true); $description->setValue($contentDescription); $description->setLabel('Description'); $form->addElement($description); $form->addElement('submit', 'submit', array('label' => $submitLabel)); return $form; }
function form() { if (!isset($this->form)) { $form = new Zend_Form(); $form->setAction($this->url()); $form->setMethod('post'); // Create and configure username element: $username = $form->createElement('text', 'username'); $username->setLabel("Username"); $username->addValidator('alnum'); $username->addValidator('regex', false, array('/^[a-z]+/')); $username->addValidator('stringLength', false, array(6, 20)); $username->setRequired(true); $username->addFilter('StringToLower'); // Create and configure password element: $password = $form->createElement('password', 'password'); $password->setLabel("Password"); $password->addValidator('StringLength', false, array(6)); $password->setRequired(true); // Add elements to form: $form->addElement($username); $form->addElement($password); // use addElement() as a factory to create 'Login' button: $form->addElement('submit', 'login', array('label' => 'Login')); // Since we're using this outside ZF, we need to supply a default view: $form->setView(new Zend_View()); $this->form = $form; } return $this->form; }
public function contactFormAction() { //create the form $form = new Zend_Form(); //this page should post back to itself $form->setAction($_SERVER['REQUEST_URI']); $form->setMethod('post'); $name = $form->createElement('text', 'name'); $name->setLabel($this->view->getTranslation('Your Name') . ': '); $name->setRequired(TRUE); $name->addFilter('StripTags'); $name->addErrorMessage($this->view->getTranslation('Your name is required!')); $name->setAttrib('size', 30); $email = $form->createElement('text', 'email'); $email->setLabel($this->view->getTranslation('Your Email') . ': '); $email->setRequired(TRUE); $email->addValidator('EmailAddress'); $email->addErrorMessage($this->view->getTranslation('Invalid email address!')); $email->setAttrib('size', 30); $subject = $form->createElement('text', 'subject'); $subject->setLabel($this->view->getTranslation('Subject') . ': '); $subject->setRequired(TRUE); $subject->addFilter('StripTags'); $subject->addErrorMessage($this->view->getTranslation('The subject is required!')); $subject->setAttrib('size', 40); $message = $form->createElement('textarea', 'message'); $message->setLabel($this->view->getTranslation('Message') . ': '); $message->setRequired(TRUE); $message->addErrorMessage($this->view->getTranslation('The message is required!')); $message->setAttrib('cols', 35); $message->setAttrib('rows', 10); $captcha = new Zend_Form_Element_Captcha('captcha', array('label' => $this->view->getTranslation('Please verify you\'re a human'), 'captcha' => array('captcha' => 'Figlet', 'wordLen' => 6, 'timeout' => 300))); $form->addElement($name); $form->addElement($email); $form->addElement($subject); $form->addElement($message); $form->addElement($captcha); $form->addElement('submit', 'submitContactForm', array('label' => $this->view->getTranslation('Send Message'))); $this->view->form = $form; if ($this->_request->isPost() && Digitalus_Filter_Post::has('submitContactForm')) { if ($form->isValid($_POST)) { //get form data $data = $form->getValues(); //get the module data $module = new Digitalus_Module(); $moduleData = $module->getData(); //render the message $this->view->data = $data; $htmlMessage = $this->view->render('public/message.phtml'); $mail = new Digitalus_Mail(); $this->view->isSent = $mail->send($moduleData->email, array($data['email'], $data['name']), $data['subject'], $htmlMessage); } } }
/** * This function creates a zend form for a login box with the relevant validation * * @return Zend_Form */ protected function getLoginForm() { $form = new Zend_Form(); $form->setAction('/cmsadmin/login')->setMethod('post'); $username = $form->createElement('text', 'username'); $username->addValidator('alnum')->addValidator('regex', false, array('/^[a-z]+/'))->addValidator('stringLength', false, array(6, 64))->setRequired(true)->addFilter('StringToLower'); $password = $form->createElement('password', 'password'); $password->addValidator('StringLength', false, array(6))->setRequired(true); $form->addElement($username)->addElement($password)->addElement('submit', 'login', array('label' => 'Login')); return $form; }
public function loginForm() { $form = new Zend_Form(); $form->setAction('user/auth')->setMethod('post'); // Create and configure username element: $username = $form->createElement('text', 'user_username'); $username->addValidator('alnum')->addValidator('regex', false, array('/^[a-z]+/'))->addValidator('stringLength', false, array(6, 20))->setRequired(true)->addFilter('StringToLower'); // Create and configure password element: $password = $form->createElement('password', 'user_password'); $password->addValidator('StringLength', false, array(6))->setRequired(true); // Add elements to form: $form->addElement($username)->addElement($password)->addElement('submit', 'login', array('label' => 'Login')); }
public function form($values = array()) { $form = new Zend_Form(); $form->setAttrib('id', 'reportingForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $fromDate = $form->createElement('text', 'fromDate', array('label' => 'reporting-index-index:fromDate')); $fromDate->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setValue(isset($values['fromDate']) ? $values['fromDate'] : ''); $toDate = $form->createElement('text', 'toDate', array('label' => 'reporting-index-index:toDate')); $toDate->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setValue(isset($values['toDate']) ? $values['toDate'] : strftime('%B %e, %Y', time())); $submit = $form->createElement('submit', 'submitButton', array('label' => 'reporting-index-index:getReport')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $form->addElements(array($fromDate, $toDate)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit)); return $form; }
function setForm() { $form=new Zend_Form; $form->setMethod('post')->setAction(''); $youtube_username = new Zend_Form_Element_Text('youtube_username'); $youtube_username->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Tên tài khoản không được để trống')); $password = new Zend_Form_Element_Text('password'); $password->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Mật khẩu không được để trống')); $youtube_gallery = new Zend_Form_Element_Text('youtube_gallery'); $youtube_gallery->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Tên album không được để trống')); $is_selected = $form->createElement("select","is_selected",array( "label" => "Kích hoạt", "multioptions"=> array( "0" => "Không", "1" => "Có"))); $youtube_username->removeDecorator('HtmlTag')->removeDecorator('Label'); $password->removeDecorator('HtmlTag')->removeDecorator('Label'); $youtube_gallery->removeDecorator('HtmlTag')->removeDecorator('Label'); $is_selected->removeDecorator('HtmlTag')->removeDecorator('Label'); $form->addElements(array($youtube_username,$password,$youtube_gallery,$is_selected)); return $form; }
function setForm() { $form=new Zend_Form; $form->setMethod('post')->setAction(''); $ads_banner = new Zend_Form_Element_Textarea('ads_banner'); $ads_banner->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Biểu ngữ không được để trống')); $ads_position = new Zend_Form_Element_Text('ads_position'); $ads_position->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Vị trí không được để trống')); $ads_name = new Zend_Form_Element_Text('ads_name'); $ads_name->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Tên quảng cáo không được để trống')); $ads_link = new Zend_Form_Element_Text('ads_link'); $ads_link->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Đường dẫn không được để trống')); $ads_position = $form->createElement("select","ads_position",array( "label" => "Vị trí", "multioptions"=> array( "1" => "Trên", "2" => "Giữa", "3" => "Trái", "4" => "Phải", "5" => "Nội dung"))); $ads_banner->removeDecorator('HtmlTag')->removeDecorator('Label'); $ads_position->removeDecorator('HtmlTag')->removeDecorator('Label'); $ads_name->removeDecorator('HtmlTag')->removeDecorator('Label'); $ads_link->removeDecorator('HtmlTag')->removeDecorator('Label'); $form->addElements(array($ads_banner,$ads_position,$ads_name,$ads_link)); return $form; }
function setForm() { $form=new Zend_Form; $form->setMethod('post')->setAction(''); $category_name = new Zend_Form_Element_Text('category_name'); $category_name->setRequired(true)->addValidator('NotEmpty',true,array('messages'=>'Tên danh mục không được để trống')); /* $category_parent_id = new Zend_Form_Element_Select('category_parent_id'); $category_parent_id->addMultiOption('', '0'); foreach($this->mDanhmuc->getListDM() as $item) { $category_parent_id->addMultiOption($item['category_name'], $item['category_id']); } */ $is_active = $form->createElement("select","is_active",array( "label" => "Kích hoạt", "multioptions"=> array( "0" => "Chưa kích hoạt", "1" => "Đã kích hoạt"))); $category_name->removeDecorator('HtmlTag')->removeDecorator('Label'); $is_active->removeDecorator('HtmlTag')->removeDecorator('Label'); $form->addElements(array($category_name,$is_active)); return $form; }
function adminloginForm() { $siteurl = 'http://' . $_SERVER['SERVER_NAME']; $form = new Zend_Form(); $form->setAction($siteurl . '/admin/auth')->setMethod('post'); // Create and configure username element: $username = $form->createElement('text', 'user_username'); $username->setLabel('Username'); $username->addValidator('alnum')->addValidator('regex', false, array('/^[a-z]+/'))->addValidator('stringLength', false, array(6, 20))->setRequired(true)->addFilter('StringToLower'); // Create and configure password element: $password = $form->createElement('password', 'user_password'); $password->setLabel('Password'); $password->addValidator('StringLength', false, array(6))->setRequired(true); // Add elements to form: $form->addElement($username)->addElement($password)->addElement('submit', 'login', array('label' => 'Login', 'class' => 'noWarn')); return $form; }
public function removeAction() { $form = new Zend_Form(); $form->setView(new Zend_View()); $form->setMethod('post'); $form->setAction(''); $form->setAttrib('class', 'devel'); $form->setAttrib('title', 'Remove wizard - ' . $this->getRequest()->getParam('name')); $handleOptions = explode(',', $this->getRequest()->getParam('handles')); $referenceOptions = explode(',', $this->getRequest()->getParam('references')); $handleOptionsUsed = explode(',', $this->getRequest()->getParam('handles_used')); $handleOptionsHidden = $form->createElement('hidden', 'handles', array('decorators' => array('ViewHelper'))); $referenceOptionsHidden = $form->createElement('hidden', 'references', array('decorators' => array('ViewHelper'))); $handleOptionsUsedHidden = $form->createElement('hidden', 'handles_used', array('decorators' => array('ViewHelper'))); $handle = $form->createElement('radio', 'handle', array('label' => 'Handle', 'required' => true, 'multiOptions' => array_combine($handleOptions, $handleOptions), 'description' => 'NOTE: This are the handles that this block appears in: ' . $this->getRequest()->getParam('handles_used'))); $reference = $form->createElement('radio', 'reference', array('label' => 'Reference', 'required' => true, 'multiOptions' => array_combine($referenceOptions, $referenceOptions))); $name = $form->createElement('text', 'name', array('label' => 'Name', 'required' => true)); $submit = $form->createElement('submit', 'submit', array('label' => 'Submit')); $form->addElements(array($handleOptionsHidden, $referenceOptionsHidden, $handleOptionsUsedHidden, $handle, $reference, $name, $submit)); if ($form->isValid($this->getRequest()->getParams())) { $localXmlWriter = Mage::getModel('devel/writer_localxml'); $localXmlWriter->addRemove($form->handle->getValue(), $form->reference->getValue(), $form->name->getValue()); $localXmlWriter->save(); die('DONE. You need to reload to see changes!'); } else { $this->loadLayout(); $this->getLayout()->getUpdate()->load('devel_layout_wizard'); $this->getLayout()->generateXml(); $this->loadLayout(); $this->getLayout()->getBlock('devel_wizard_form')->setForm($form); $this->renderLayout(); } }
public function getForm() { $form = new Zend_Form(); $form->setAction('/index/login')->setMethod('post')->setAttrib('id', 'formLogin'); // Crea un y configura el elemento username $username = $form->createElement('text', 'username', array('label' => 'Nombre de Usuario')); $username->addValidator('notEmpty', true, array('messages' => array('isEmpty' => 'Campo requerido')))->addValidator('regex', true, array('pattern' => '/^[(a-zA-Z0-9)]+$/', 'messages' => array('regexNotMatch' => 'Caracteres invalidos')))->addValidator('stringLength', false, array(5, 20, 'messages' => "5 a 20 caracteres"))->setRequired(true)->addFilter('StringToLower'); $username->setDecorators(array('ViewHelper', 'Description', 'Errors', array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')), array(array('td' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'td')))); // Crea y configura el elemento password: $password = $form->createElement('password', 'password', array('label' => 'Contraseña')); $password->addValidator('notEmpty', true, array('messages' => array('isEmpty' => 'Campo requerido')))->addValidator('stringLength', false, array(5, 20, 'messages' => "5 a 20 caracteres"))->setRequired(true); $password->setDecorators(array('ViewHelper', 'Description', 'Errors', array(array('elementDiv' => 'HtmlTag'), array('tag' => 'div')), array(array('td' => 'HtmlTag'), array('tag' => 'td')), array('Label', array('tag' => 'td')))); $recordarme = $form->createElement('checkbox', 'remember', array('label' => 'Recordar mi Sesión')); $recordarme->setDecorators(array('ViewHelper', 'Description', 'Errors', array('Label', array('placement' => 'APPEND')))); // Añade los elementos al formulario: $form->addElement($username)->addElement($password)->addElement($recordarme)->addElement('submit', 'login', array('label' => 'Ingresar')); return $form; }
/** * Создание элемента формы * * @see Zend_Form::createElement() */ public function createElement($type, $name, $options = null) { $element = parent::createElement($type, $name, $options); //$element->removeDecorator('Label'); //$element->removeDecorator('HtmlTag'); //$element->removeDecorator('DtDdWrapper'); //$element->removeDecorator('Description'); return $element; }
/** * The main workshop page. It has the list of all the workshops that are * available in the system. * */ public function indexAction() { $this->view->acl = array('workshopList' => $this->_helper->hasAccess('workshop-list')); $get = Zend_Registry::get('getFilter'); $form = new Zend_Form(); $form->setAttrib('id', 'workshopForm')->setMethod(Zend_Form::METHOD_GET)->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'filterForm')), 'Form')); $searchField = $form->createElement('text', 'search', array('label' => 'workshop-index-index:searchWorkshops')); $searchField->setRequired(false)->addFilter('StringTrim')->addFilter('StripTags')->setValue(isset($get->search) ? $get->search : ''); $category = new Category(); $categoryList = $category->fetchAll(null, 'name'); $categories = $form->createElement('select', 'categoryId'); $categories->addMultiOption('', '-- Search By Category -- '); foreach ($categoryList as $c) { $categories->addMultiOption($c['categoryId'], $c['name']); } $categories->setValue(isset($get->categoryId) ? $get->categoryId : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'workshop-index-index:search')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $form->addElements(array($searchField, $categories)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit)); $this->view->form = $form; $searchTerm = new Search_Term(); $workshops = array(); if ($get->search != '' || $get->categoryId != 0) { $workshop = new Workshop(); $query = new Zend_Search_Lucene_Search_Query_MultiTerm(); if ($get->search != '') { $query->addTerm(new Zend_Search_Lucene_Index_Term($get->search), true); } if ($get->categoryId != 0) { $query->addTerm(new Zend_Search_Lucene_Index_Term($get->categoryId, 'categoryId'), true); } $workshops = $workshop->search($query); $searchTerm->increment($get->search); $this->view->searchTerm = $get->search; } $this->view->workshops = $workshops; $this->view->topTerms = $searchTerm->getTopSearchTerms(10); $this->view->layout()->setLayout('search'); $this->view->layout()->rightContent = $this->view->render('index/top-terms.phtml'); $this->view->headScript()->appendFile($this->view->baseUrl() . '/scripts/jquery.autocomplete.js'); $this->view->headLink()->appendStylesheet($this->view->baseUrl() . '/css/jquery.autocomplete.css'); $this->_helper->pageTitle("workshop-index-index:title"); }
/** * Create an element. * * Acts as a factory for creating elements. Elements created with this * method will not be attached to the form, but will contain element * settings as specified in the form object (including plugin loader * prefix paths, default decorators, etc.). * * This extends the version in Zend_Form and turns off translation * and decorators by default. * * @param string $type Form element type. * @param string $name Name of the element. * @param array|Zend_Config $options Set of configuration options. * * @return Zend_Form_Element */ public function createElement($type, $name, $options = null) { // Turn off the translator by default because we'll be using PHPTAL. if (!isset($options['disableTranslator'])) { $options['disableTranslator'] = true; } // Turn off loading any decorators because they are unneeded and we use // decorators to specify what TAL macro to use. $options['disableLoadDefaultDecorators'] = true; return parent::createElement($type, $name, $options); }
function employeeAddForm() { $form = new Zend_Form(); $form->setAction('http://localhost/zend/index/registeruser')->setMethod('post'); // Create and configure username element: $name = $form->createElement('text', 'user_name'); $name->setLabel('Name'); $name->setRequired(true)->addFilter('StringToLower'); $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email')->addFilter('StringToLower')->setRequired(true)->addValidator('NotEmpty', true)->addValidator('EmailAddress'); $username = $form->createElement('text', 'user_username'); $username->setLabel('Username'); $username->addValidator('alnum')->addValidator('regex', false, array('/^[a-z]+/'))->addValidator('stringLength', false, array(6, 20))->setRequired(true)->addFilter('StringToLower'); // Create and configure password element: $password = $form->createElement('password', 'user_password'); $password->setLabel('Password'); $password->addValidator('StringLength', false, array(6))->setRequired(true); // Add elements to form: $form->addElement($name)->addElement($email)->addElement($username)->addElement($password)->addElement('submit', 'login', array('label' => 'Login')); return $form; }
public function __construct($options = array()) { parent::__construct($options); $acl = Zend_Registry::get('acl'); $form = new Zend_Form(); $form->setAttrib('id', 'account')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $authAdapter = new Ot_Model_DbTable_AuthAdapter(); $adapters = $authAdapter->fetchAll(null, 'displayOrder'); // Realm Select box $realmSelect = $form->createElement('select', 'realm', array('label' => 'Login Method')); foreach ($adapters as $adapter) { $realmSelect->addMultiOption($adapter->adapterKey, $adapter->name . (!$adapter->enabled ? ' (Disabled)' : '')); } $realmSelect->setValue(isset($default['realm']) ? $default['realm'] : ''); // Create and configure username element: $username = $form->createElement('text', 'username', array('label' => 'model-account-username')); $username->setRequired(true)->addFilter('StringTrim')->addFilter('Alnum')->addFilter('StripTags')->addValidator('StringLength', false, array(3, 64))->setAttrib('maxlength', '64')->setValue(isset($default['username']) ? $default['username'] : ''); $submit = $form->createElement('submit', 'submit', array('label' => 'Masquerade')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $form->addElements(array($realmSelect, $username, $submit)); }
/** * Gets the form for adding and editing a location * * @param array $values * @return Zend_Form */ public function form($values = array()) { $form = new Zend_Form(); $form->setAttrib('id', 'locationTypeForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $name = $form->createElement('text', 'name', array('label' => 'Name:')); $name->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setValue(isset($values['name']) ? $values['name'] : ''); // $status = $form->createElement('select', 'status', array('label' => 'Status:')); // $status->addMultiOption('enabled', 'Enabled'); // $status->addMultiOption('disabled', 'Disabled'); // $status->setValue((isset($values['status']) ? $values['status'] : 'enabled')); // $capacity = $form->createElement('text', 'capacity', array('label' => 'Capacity:')); // $capacity->setRequired(true) // ->addFilter('StringTrim') // ->addFilter('StripTags') // ->addValidator('Digits') // ->setAttrib('maxlength', '64') // ->setValue((isset($values['capacity']) ? $values['capacity'] : '')); // $address = $form->createElement('text', 'address', array('label' => 'Address:')); // $address->setRequired(true) // ->addFilter('StringTrim') // ->addFilter('StripTags') // ->setAttrib('maxlength', '255') // ->setValue((isset($values['address']) ? $values['address'] : '')); $description = $form->createElement('textarea', 'description', array('label' => 'Description:')); $description->setRequired(false)->addFilter('StringTrim')->setAttrib('style', 'width: 95%; height: 300px;')->setValue(isset($values['description']) ? $values['description'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($name, $description)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); if (isset($values['typeId'])) { $locationId = $form->createElement('hidden', 'typeId'); $locationId->setValue($values['typeId']); $locationId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($locationId); } return $form; }
public function indexAction() { /* * * @todo email site admin when inserted * */ $this->_model = new Joobsbox_Model_Jobs(); // <createForm> $form = new Zend_Form(); $form->setAction($_SERVER['REQUEST_URI'])->setMethod('post')->setAttrib("id", "formPublish"); $title = $form->createElement('text', 'title')->setLabel('Job title:')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('notEmpty')->setDescription('Ex: "Flash Designer" or "ASP.NET Programmer"')->setRequired(true); $company = $form->createElement('text', 'company')->setLabel('Company:')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('notEmpty')->setRequired(true); $location = $form->createElement('text', 'location')->setLabel('Location:')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('notEmpty')->setDescription('Example: "London, Paris, Berlin, New York"')->setRequired(true); $categories[0] = $this->view->translate("Choose..."); foreach ($this->_model->fetchCategories()->getIndexNamePairs() as $key => $value) { $categories[$key] = $value; } $greaterThan = new Zend_Validate_GreaterThan(false, array('0')); $greaterThan->setMessage($this->view->translate("Choosing a category is mandatory.")); $category = $form->createElement('select', 'category')->setLabel('Category:')->addValidator('notEmpty')->addValidator($greaterThan)->setRequired(true)->setMultiOptions($categories); $description = $form->createElement('textarea', 'description')->setLabel('Job description:')->setDescription('HTML code is not accepted. Length must be less than 4000 characters.')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('notEmpty')->setRequired(true); $application = $form->createElement('text', 'application')->setLabel('Means of application:')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('notEmpty')->setDescription('Ex: "Send CV to email ..." or "Apply online at URL ..."')->setRequired(true); $submit = $form->createElement('submit', 'submit')->setLabel("Add"); $form->addElement($title)->addElement($company)->addElement($location)->addElement($category)->addElement($description)->addElement($application); $publishNamespace = new Zend_Session_Namespace('PublishJob'); if (isset($publishNamespace->editJobId)) { $jobData = $this->_model->fetchJobById($publishNamespace->editJobId); $title->setValue($jobData['title']); $company->setValue($jobData['company']); $location->setValue($jobData['location']); $category->setValue($jobData['categoryid']); $description->setValue($jobData['description']); $application->setValue($jobData['toapply']); $exp = $form->createElement('text', 'expirationdate')->setLabel('Expiration date:')->addFilter('StripTags')->addFilter('StringTrim')->addValidator('notEmpty')->setRequired(true)->setValue(date("m/d/Y", $jobData['expirationdate'])); $form->addElement($exp); $submit->setLabel('Modify'); } $form->addElement($submit); $this->form = $form; // </createForm> // Render the form $this->view->form = $form->render; if ($this->getRequest()->isPost()) { $this->validateForm(); return; } $this->view->form = $this->form->render(); }
/** * Present a login form and handle user authentication. */ public function loginAction() { /* * Build the login form */ $form = new Zend_Form(); $form->setMethod('post'); $username = $form->createElement('text', 'username'); $username->setLabel($this->view->translate->_('Username')); $username->setRequired(true); $username->addValidator('alnum'); $password = $form->createElement('password', 'password'); $password->setLabel($this->view->translate->_('Password')); $password->setRequired(true); $form->addElement($username); $form->addElement($password); $form->addElement('submit', 'login', array('label' => $this->view->translate->_('Login'))); /* * Handle authentication */ if ($this->getRequest()->isPost()) { $formData = $this->getRequest()->getPost(); if ($form->isValid($formData)) { try { Model_DbTable_User::authenticate($form->getValue('username'), $form->getValue('password')); /* * Set the current user session */ $user = Model_DbTable_User::findByUsername($form->getValue('username')); $currentUser = new Zend_Session_Namespace('currentUser'); $currentUser->id = $user->id; $currentUser->username = $user->username; $currentUser->apiKey = $user->apiKey; $currentUser->language = $user->language; $currentUser->skin = $user->skin; $currentUser->isAdmin = $user->isAdmin; /* * Redirect back to the index page. */ $this->_helper->_redirector->goToRouteAndExit(array('controller' => 'index', 'action' => 'index')); } catch (Exception $e) { $this->view->errorMessage = $this->view->translate->_('Login failed.') . ' ' . $e->getMessage(); } } else { $this->view->errorMessage = $this->view->translate->_('Login failed.') . ' ' . $this->view->translate->_('Please completely fill out the login form.'); $form->populate($formData); } } $this->view->headTitle($this->view->translate->_('Login')); $this->view->form = $form; }
public function getForm() { $db = $this->db; $form = new Zend_Form(); $form->setAction('/Account'); $form->setMethod('get'); $form->setName('search'); $accountName = $form->createElement('text', 'name'); $accountName->setLabel('Name'); $city = $form->createElement('text', 'city'); $city->setLabel('City'); $state = $form->createElement('text', 'state'); $state->setLabel('State'); $country = $form->createElement('text', 'country'); $country->setLabel('Country'); $assignedTo = new Zend_Dojo_Form_Element_FilteringSelect('assignedTo'); $assignedTo->setLabel('Accounts assigned to')->setAutoComplete(true)->setStoreId('accountStore')->setStoreType('dojo.data.ItemFileReadStore')->setStoreParams(array('url' => '/user/jsonstore'))->setAttrib("searchAttr", "email")->setRequired(false); $branchId = new Zend_Dojo_Form_Element_FilteringSelect('branchId'); $branchId->setLabel('Accounts Of Branch')->setAutoComplete(true)->setStoreId('branchStore')->setStoreType('dojo.data.ItemFileReadStore')->setStoreParams(array('url' => '/jsonstore/branch'))->setAttrib("searchAttr", "branch_name")->setRequired(false); $submit = $form->createElement('submit', 'submit')->setLabel('Search')->setAttrib("class", "submit_button"); $form->addElements(array($name, $city, $assignedTo, $branchId, $submit)); return $form; }
public function form($values = array()) { $form = new Zend_Form(); $form->setAttrib('id', 'categoryForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $name = $form->createElement('text', 'name', array('label' => 'Name:')); $name->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setValue(isset($values['name']) ? $values['name'] : ''); $description = $form->createElement('textarea', 'description', array('label' => 'Description:')); $description->setRequired(false)->addFilter('StringTrim')->setAttrib('style', 'width: 95%; height: 300px;')->setValue(isset($values['description']) ? $values['description'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($name, $description)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); if (isset($values['categoryId'])) { $categoryId = $form->createElement('hidden', 'categoryId'); $categoryId->setValue($values['categoryId']); $categoryId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($categoryId); } return $form; }
/** * Adds default decorators if none are specified in the options and then calls Zend_Form::createElement() * (non-PHPdoc) * @see Zend_Form::createElement() */ public function createElement($type, $name, $options = null) { // If we haven't specified our own decorators, add the default ones in. if (is_array($this->_elementDecorators)) { if (null === $options) { $options = array('decorators' => $this->_elementDecorators); } elseif ($options instanceof Zend_Config) { $options = $options->toArray(); } if (is_array($options) && !array_key_exists('decorators', $options)) { $options['decorators'] = $this->_elementDecorators; } } return parent::createElement($type, $name, $options); }
function loginForm() { $siteurl = 'http://' . $_SERVER['SERVER_NAME']; $form = new Zend_Form(); $form->setAction($siteurl . '/user/auth')->setMethod('post'); // Create and configure username element: $username = $form->createElement('text', 'user_username'); //$username->setValue('Username'); $username->setLabel(''); $username->setAttribs(array('class' => 'login user')); $username->addValidator('alnum')->addValidator('regex', false, array('/^[a-z]+/'))->addValidator('stringLength', false, array(6, 20))->setRequired(true)->addFilter('StringToLower'); // Create and configure password element: $password = $form->createElement('password', 'user_password'); $password->setAttribs(array('class' => 'login password')); $password->addValidator('StringLength', false, array(6))->setRequired(true); // use addElement() as a factory to create 'Login' button: $submit = $form->createElement('submit', 'Login'); $submit->setAttrib('type', 'submit')->setAttrib('value', 'Sign In'); // buttons do not need labels $submit->setDecorators(array(array('ViewHelper'), array('Description'), array('HtmlTag', array('tag' => 'div', 'class' => 'button green')))); // Add elements to form: $form->addElement($username)->addElement($password)->addElement($submit); return $form; }
public function testRenderWithHidden() { $form = new Zend_Form(); $form->setName('Test'); $form->addElement('submit', 'Remove'); $element = $form->createElement('hidden', 'Id'); $element->setValue(10); $form->addElement($element); $decorator = new Application_Form_Decorator_RemoveButton(); $decorator->setElement($form); $decorator->setSecondElement($element); $output = $decorator->render('content'); // Output wird an content dran gehängt $this->assertEquals('content' . '<input type="hidden" name="Id" id="Id" value="10" />' . '<input type="submit" name="Remove" id="Remove" value="Remove" />', $output); }
public function getLoginForm() { $form = new Zend_Form(); $form->setMethod('post'); $email = $form->createElement('text', 'email'); $email->setRequired(true)->addFilter('StringToLower'); $email->addValidator(new Zend_Validate_EmailAddress()); $email->setLabel('Email Address'); $form->addElement($email); $password = $form->createElement('password', 'password'); $password->setRequired(true)->addFilter('StringToLower'); $password->setLabel('Password'); $form->addElement($password); $form->addElement('submit', 'register', array('label' => 'Login!')); return $form; }
public function addAttendeeForm($values = array()) { if (!isset($values['eventId'])) { throw new Ot_Exception_Input('The event ID must be provided.'); } $form = new Zend_Form(); $form->setAttrib('id', 'locationForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $eventId = $form->createElement('hidden', 'eventId'); $eventId->setValue($values['eventId']); $eventId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($eventId); $type = $form->createElement('select', 'type', array('label' => 'How to Add:')); $type->addMultiOption('firstAvailable', 'First Available Spot')->addMultiOption('attending', 'Add To Attending List')->setValue(isset($values['type']) ? $values['type'] : ''); // get all the users available for the instructor list $otAccount = new Ot_Account(); $accounts = $otAccount->fetchAll(null, array('lastName', 'firstName'))->toArray(); $userList = array(); foreach ($accounts as $a) { $userList[$a['accountId']] = $a['lastName'] . ", " . $a['firstName']; } // remove anyone who's either in the attendee list, waitlist, or an instructor // for this event so they can't be added to the list $attendee = new Event_Attendee(); $attendeeList = $attendee->getAttendeesForEvent($values['eventId'], 'attending'); $waitlist = $attendee->getAttendeesForEvent($values['eventId'], 'waitlist'); $instructors = $this->getInstructorsForEvent($values['eventId']); foreach ($attendeeList as $a) { unset($userList[$a['accountId']]); } foreach ($waitlist as $w) { unset($userList[$w['accountId']]); } foreach ($instructors as $i) { unset($userList[$i['accountId']]); } $users = $form->createElement('multiselect', 'users', array('label' => 'User Search:')); $users->setMultiOptions($userList)->setAttrib('size', 10)->setValue(isset($values['accountIds']) ? $values['accountIds'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($type, $users)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); return $form; }
public function createElement($type, $name, $options = null) { if (null === $options || !is_array($options)) { $options = array('prefixPath' => array(array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'Application_', 'path' => 'Application/'))); } elseif (is_array($options)) { if (array_key_exists('prefixPath', $options)) { if (isset($options['prefixPath']['prefix'])) { $options['prefixPath'] = array(array('prefix' => $options['prefixPath']['prefix'], 'path' => $options['prefixPath']['path']), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'Application_', 'path' => 'Application/')); } else { $options['prefixPath'][] = array(array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'Application_', 'path' => 'Application/')); } } else { $options['prefixPath'] = array(array('prefix' => 'ZendX_', 'path' => 'ZendX/'), array('prefix' => 'HausDesign_', 'path' => 'HausDesign/'), array('prefix' => 'Application_', 'path' => 'Application/')); } } return parent::createElement($type, $name, $options); }
/** * แก้ไขให้ โหลด App Element ได้ * ยังหาวิธีที่ถูกต้องไม่ได้เลยใช้วิธี Addhoc ไปก่อน * @param type $type * @param type $name * @param type $options * @return type * @throws Zend_Form_Exception */ public function createElement($type, $name, $options = null) { // ถ้าไม่พบ Zend_Form_Element_ ให้ไปหาใน App_Form_Element_ $class = "Zend_Form_Element_" . $type; if (!class_exists($class)) { if (!is_string($type)) { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('Element type must be a string indicating type'); } if (!is_string($name)) { require_once 'Zend/Form/Exception.php'; throw new Zend_Form_Exception('Element name must be a string'); } $prefixPaths = array(); $prefixPaths['decorator'] = $this->getPluginLoader('decorator')->getPaths(); if (!empty($this->_elementPrefixPaths)) { $prefixPaths = array_merge($prefixPaths, $this->_elementPrefixPaths); } if ($options instanceof Zend_Config) { $options = $options->toArray(); } if (null === $options || !is_array($options)) { $options = array('prefixPath' => $prefixPaths); if (is_array($this->_elementDecorators)) { $options['decorators'] = $this->_elementDecorators; } } elseif (is_array($options)) { if (array_key_exists('prefixPath', $options)) { $options['prefixPath'] = array_merge($prefixPaths, $options['prefixPath']); } else { $options['prefixPath'] = $prefixPaths; } if (is_array($this->_elementDecorators) && !array_key_exists('decorators', $options)) { $options['decorators'] = $this->_elementDecorators; } } $class = App_Form_Element_ . $type; $element = new $class($name, $options); } else { $element = parent::createElement($type, $name, $options); } return $element; }