/** * Upload a new GRF */ public function uploadAction() { $form = new App_Form(array('action' => $this->_helper->url->url(), 'method' => 'post', 'enctype' => 'multipart/form-data', 'elements' => array('grf_file' => array('file', array('label' => 'GRF-File', 'required' => true, 'destination' => UPLOADS_PATH, 'validators' => array(array('count', false, array('1')), array('extension', false, array('grf'))))), 'readme_file' => array('file', array('label' => 'Readme', 'required' => true, 'destination' => UPLOADS_PATH, 'validators' => array(array('count', false, array('1')), array('extension', false, array('txt'))))), 'terms_accepted' => array('checkbox', array('label' => 'Herby i confirm that the requirements noted in the terms & conditions are met', 'required' => true)), 'submit' => array('submit', array('label' => 'Upload GRF'))))); if ($this->getRequest()->isPost() && $form->isValid($_POST)) { $data = $form->getValues(); die(print_r($data)); } $this->view->form = $form; }
/** * Overrides render() in App_Form * * @param Zend_View_Interface $view * @access public * @return string */ public function render(Zend_View_Interface $view = NULL) { foreach ($this->getElements() as $element) { $this->_replaceLabel($element); switch (TRUE) { case $element instanceof Zend_Form_Element_Hidden: case $element instanceof Zend_Form_Element_Hash: $this->_addHiddenClass($element); break; case $element instanceof Zend_Form_Element_Checkbox: $this->_appendLabel($element); break; case $element instanceof Zend_Form_Element_MultiCheckbox: $element->getDecorator('Label')->setOption('tagOptions', array('class' => 'checkboxGroup')); $element->getDecorator('HtmlTag')->setOption('class', 'checkboxGroup'); break; } } $this->_cancelLink(); $this->getDecorator('HtmlTag')->setOption('class', 'zend_form clearfix'); if (NULL === $this->getAttrib('id')) { $controllerName = Zend_Registry::get('controllerName'); $actionName = Zend_Registry::get('actionName'); $this->setAttrib('id', $controllerName . '-' . $actionName); } return parent::render($view); }
/** * Overrides render() in App_Form * * @param Zend_View_Interface $view * @access public * @return string */ public function render(Zend_View_Interface $view = NULL) { $this->clearDecorators(); $this->setDecorators(array(array('ViewScript', array('viewScript' => $this->_partial, 'form' => $this, 'view' => $this->getView())))); foreach ($this->getElements() as $element) { $element->clearDecorators(); if ($element instanceof Zend_Form_Element_File) { $element->setDecorators(array(array('File'), array('Errors'))); } else { $element->setDecorators(array(array('ViewHelper'), array('Errors'))); } $element->getView()->getHelper('FormErrors')->setElementStart('<strong class="error"><em>'); $element->getView()->getHelper('FormErrors')->setElementEnd('</em></strong>'); $element->getView()->getHelper('FormErrors')->setElementSeparator('</em><em>'); } if (NULL === $this->getAttrib('id')) { $controllerName = Zend_Registry::get('controllerName'); $actionName = Zend_Registry::get('actionName'); $this->setAttrib('id', $controllerName . '-' . $actionName); } return parent::render($view); }
public function init() { $model = new Model_Wep(); $this->setAttrib('id', 'simplified-default-form')->setIsArray(true); $form = array(); $requiredMessage = new Iati_Form_Element_Note('form-message'); $requiredMessage->setValue("If you fill this section, the fields marked <span class='form-required'>*</span> must be filled.")->setOrder(-1); $defaultMessage = new Iati_Form_Element_Note('message'); $defaultMessage->setValue("The fields marked <span class='form-required'>*</span> must be filled."); $form['activity_id'] = new Zend_Form_Element_Hidden('activity_id'); $form['activity_id']->setValue($this->data['activity_id']); $form['identifier_id'] = new Zend_Form_Element_Hidden('identifier_id'); $form['identifier_id']->setValue($this->data['identifier_id']); $form['identifier'] = new Zend_Form_Element_Text('identifier'); $form['identifier']->setLabel('Project Identifier')->setRequired()->setValue($this->data['identifier'])->setAttrib('class', 'form-text'); $form['title_id'] = new Zend_Form_Element_Hidden('title_id'); $form['title_id']->setValue($this->data['title_id']); $form['title'] = new Zend_Form_Element_Text('title'); $form['title']->setLabel('Title')->setRequired()->setValue($this->data['title'])->setAttrib('class', 'form-text'); $form['description_id'] = new Zend_Form_Element_Hidden('description_id'); $form['description_id']->setValue($this->data['description_id']); $form['description'] = new Zend_Form_Element_Textarea('description'); $form['description']->setLabel('Description')->setRequired()->setValue($this->data['description'])->setAttrib('COLS', '40')->setAttrib('ROWS', '4')->setAttrib('class', 'form-text'); $fundingOrgData = $this->data['funding_org']; $fundingOrgs = ''; if ($fundingOrgData && is_array($fundingOrgData)) { $fundingOrgs = implode(',', $fundingOrgData); } $form['funding_org'] = new Zend_Form_Element_Hidden('funding_org'); $form['funding_org']->setValue($fundingOrgs)->setLabel('Funding Organisation')->setAttrib('style', 'width:300px'); /* $form['funding_org'] = new Zend_Form_Element_Text('funding_org'); $form['funding_org']->setLabel('Funding Organisation') ->setRequired() ->setValue(array('test')) ->setAttrib('class', 'form-text'); */ $form['start_date_id'] = new Zend_Form_Element_Hidden('start_date_id'); $form['start_date_id']->setValue($this->data['start_date_id']); $form['start_date'] = new Zend_Form_Element_Text('start_date'); $form['start_date']->setLabel('Actual Start Date')->setRequired()->setValue($this->data['start_date'])->setAttrib('class', 'form-text datepicker'); $form['end_date_id'] = new Zend_Form_Element_Hidden('end_date_id'); $form['end_date_id']->setValue($this->data['end_date_id']); $form['end_date'] = new Zend_Form_Element_Text('end_date'); $form['end_date']->setLabel('Actual End Date')->setRequired()->setValue($this->data['end_date'])->addValidator(new App_Validate_EndDate($form['start_date']))->setAttrib('class', 'form-text datepicker'); $sectorCodes = $model->getCodeArray('Sector', '', 1); $sectors = $this->data['sector']; if ($sectors) { foreach ($sectors as $sector) { $sectorData[] = $sector['sector']; } } $form['sector'] = new Zend_Form_Element_Select('sector'); $form['sector']->setLabel('Sector')->addMultiOptions($sectorCodes)->setRegisterInArrayValidator(false)->setValue($sectorData)->setAttrib('multiple', 'true')->setAttrib('class', 'form-text'); $form['status_id'] = new Zend_Form_Element_Hidden('status_id'); $form['status_id']->setValue($this->data['status_id']); $statuses = $model->getCodeArray('ActivityStatus', '', 1); $form['status'] = new Zend_Form_Element_Select('status'); $form['status']->setLabel('Activity Status')->addMultiOption('', 'Select anyone')->addMultiOptions($statuses)->setValue($this->data['status'])->setRegisterInArrayValidator(false)->setAttrib('class', 'form-select')->setAttrib('style', 'width:300px'); $this->addElements($form); foreach ($form as $item_name => $element) { $form[$item_name]->addDecorators(array(array('HtmlTag', array('tag' => '<div>', 'placement' => 'PREPEND', 'class' => 'help simplified-' . $item_name)), array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'clearfix form-item')))); } // location $locationForm = new App_Form(); $locationForm->removeDecorator('form'); if ($this->data['location']) { foreach ($this->data['location'] as $key => $locationData) { $location = new Simplified_Form_Activity_Location(array('data' => $locationData, 'count' => $key)); $locationForm->addSubForm($location, 'location' . $key); $location->removeDecorator('form'); } } else { $location = new Simplified_Form_Activity_Location(array('data' => $locationData)); $locationForm->addSubForm($location, 'location'); $location->removeDecorator('form'); } $add = new Iati_Form_Element_Note('add'); $add->addDecorator('HtmlTag', array('tag' => 'span', 'class' => 'simplified-add-more')); $add->setValue("<a href='#' class='button' value='Location'> Add More</a>"); $locationForm->addElement($add); $locationForm->addElement($requiredMessage); $this->addSubForm($locationForm, 'location_wrapper'); // Budget $budgetForm = new App_Form(); $budgetForm->removeDecorator('form'); if ($this->data['budget']) { foreach ($this->data['budget'] as $key => $budgetData) { $budget = new Simplified_Form_Activity_Budget(array('data' => $budgetData, 'count' => $key)); $budgetForm->addSubForm($budget, 'budget' . $key); $budget->removeDecorator('form'); } } else { $budget = new Simplified_Form_Activity_Budget(array('data' => $budgetData)); $budgetForm->addSubForm($budget, 'budget'); $budget->removeDecorator('form'); } $add = new Iati_Form_Element_Note('add'); $add->addDecorator('HtmlTag', array('tag' => 'span', 'class' => 'simplified-add-more')); $add->setValue("<a href='#' class='button' value='Budget'> Add More</a>"); $budgetForm->addElement($add); $budgetForm->addElement($requiredMessage); $this->addSubForm($budgetForm, 'budget_wrapper'); /** * @deprecated */ /* // Commitment $commForm = new App_Form(); $commForm->removeDecorator('form'); if($this->data['commitment']){ foreach($this->data['commitment'] as $key=>$commitmentData){ $commitment = new Simplified_Form_Activity_Transaction_Commitment(array('data' => $commitmentData , 'count' => $key)); $commForm->addSubForm($commitment , 'commitment'.$key); $commitment->removeDecorator('form'); } } else { $commitment = new Simplified_Form_Activity_Transaction_Commitment(); $commForm->addSubForm($commitment , 'commitment'); $commitment->removeDecorator('form'); } $add = new Iati_Form_Element_Note('add'); $add->addDecorator('HtmlTag', array('tag' => 'span' , 'class' => 'simplified-add-more')); $add->setValue("<a href='#' class='button' value='Transaction_Commitment'> Add More</a>"); $commForm->addElement($add); $this->addSubForm($commForm , 'commitment_wrapper'); */ // incommingFund $incommForm = new App_Form(); $incommForm->removeDecorator('form'); if ($this->data['incommingFund']) { foreach ($this->data['incommingFund'] as $key => $incommingFundData) { $incommingFund = new Simplified_Form_Activity_Transaction_IncommingFund(array('data' => $incommingFundData, 'count' => $key)); $incommForm->addSubForm($incommingFund, 'incommingFund' . $key); $incommingFund->removeDecorator('form'); } } else { $incommingFund = new Simplified_Form_Activity_Transaction_IncommingFund(); $incommForm->addSubForm($incommingFund, 'incommingFund'); $incommingFund->removeDecorator('form'); } $add = new Iati_Form_Element_Note('add'); $add->addDecorator('HtmlTag', array('tag' => 'span', 'class' => 'simplified-add-more')); $add->setValue("<a href='#' class='button' value='Transaction_IncommingFund'> Add More</a>"); $incommForm->addElement($add); $incommForm->addElement($requiredMessage); $this->addSubForm($incommForm, 'incomming_fund_wrapper'); // Expenditure $expForm = new App_Form(); $expForm->removeDecorator('form'); if ($this->data['expenditure']) { foreach ($this->data['expenditure'] as $key => $expenditureData) { $expenditure = new Simplified_Form_Activity_Transaction_Expenditure(array('data' => $expenditureData, 'count' => $key)); $expForm->addSubForm($expenditure, 'expenditure' . $key); $expenditure->removeDecorator('form'); } } else { $expenditure = new Simplified_Form_Activity_Transaction_Expenditure(); $expForm->addSubForm($expenditure, 'expenditure'); $expenditure->removeDecorator('form'); } $add = new Iati_Form_Element_Note('add'); $add->addDecorator('HtmlTag', array('tag' => 'span', 'class' => 'simplified-add-more')); $add->setValue("<a href='#' class='button' value='Transaction_Expenditure'> Add More</a>"); $expForm->addElement($add); $expForm->addElement($requiredMessage); $this->addSubForm($expForm, 'expenditure_wrapper'); // document $documentForm = new App_Form(); $documentForm->removeDecorator('form'); if ($this->data['document']) { foreach ($this->data['document'] as $key => $documentData) { $document = new Simplified_Form_Activity_Document(array('data' => $documentData, 'count' => $key)); $documentForm->addSubForm($document, 'document' . $key); $document->removeDecorator('form'); } } else { $document = new Simplified_Form_Activity_Document(array('data' => $documentData)); $documentForm->addSubForm($document, 'document'); $document->removeDecorator('form'); } $add = new Iati_Form_Element_Note('add'); $add->addDecorator('HtmlTag', array('tag' => 'span', 'class' => 'simplified-add-more')); $add->setValue("<a href='#' class='button' value='Document'> Add More</a>"); $documentForm->addElement($add); $documentForm->addElement($requiredMessage); $this->addSubForm($documentForm, 'document_wrapper'); // Result $resultForm = new App_Form(); $resultForm->removeDecorator('form'); if ($this->data['result']) { foreach ($this->data['result'] as $key => $resultData) { $result = new Simplified_Form_Activity_Result(array('data' => $resultData, 'count' => $key)); $resultForm->addSubForm($result, 'result' . $key); $result->removeDecorator('form'); } } else { $result = new Simplified_Form_Activity_Result(array('data' => $resultData)); $resultForm->addSubForm($result, 'result'); $result->removeDecorator('form'); } $add = new Iati_Form_Element_Note('add'); $add->addDecorator('HtmlTag', array('tag' => 'span', 'class' => 'simplified-add-more')); $add->setValue("<a href='#' class='button' value='Result'> Add More</a>"); $resultForm->addElement($add); $resultForm->addElement($requiredMessage); $this->addSubForm($resultForm, 'result_wrapper'); foreach ($form as $item_name => $element) { $form[$item_name]->addDecorators(array(array(array('wrapperAll' => 'HtmlTag'), array('tag' => 'div', 'class' => 'clearfix form-item')))); } $this->addElement('submit', 'save', array('label' => 'Save', 'required' => false, 'class' => 'simplified-save-button')); $this->addDecorators(array(array('ViewScript', array('viewScript' => 'default/viewscripts/simplified.phtml')))); $this->addElement($defaultMessage); }
/** * Returns an elemnt with StripTags Filter. * @param Zend_Form_Element $element * @param String $name * @param Array $options * @return Core_Form_Abstract */ public function addElement($element, $name = null, $options = null) { parent::addElement($element, $name, $options); $stripTagsFilter = new Zend_Filter_StripTags(); if (is_string($element)) { if ($this->getElement($name)->getFilter('StripTags') === false) { $this->getElement($name)->addFilter($stripTagsFilter); } } elseif ($element instanceof Zend_Form_Element) { if ($element->getFilter('StripTags') === false) { $element->addFilter($stripTagsFilter); } } return $this; }
function render() { $this->view->headLink()->appendStylesheet('/css/express-table/style.css'); $formGroups = $this->_config->getFormGroups($this->_uiName); // print_r($formGroups); ?> <style > dt{ display:none; } </style> <form id='<?php echo $this->_form_id; ?> ' method="post" class='form-horizontal' role="form" action="<?php echo $this->view->url(); ?> " > <?php $index = 0; foreach ($formGroups as $groups) { ?> <fieldset> <h5><?php echo $groups['label']; ?> </h5> <?php foreach ($this->_config->getFormGroupElements($this->_uiName, $index) as $elementid) { $prop = $this->_config->getPropByName($elementid); $element = $this->getFormElement($elementid, $prop); $isRequired = true; if ($element instanceof Zend_Form_Element) { $isRequired = $element->isRequired(); } if (!$prop->isAllowEdit) { continue; } $style = ""; if ($prop->input == 'hidden') { $style = 'display: none;'; } ?> <div class="form-group"> <label for="<?php echo $elementid; ?> " class="col-sm-2 control-label"> <?php echo $this->view->translate($prop->label); ?> <?php if ($isRequired and $prop->modification == 'changeable') { echo "<span style='color: red;'>*<span>"; } ?> </label> <div class="col-sm-10"> <?php if (true == $this->_form->isEditForm()) { if ('readonly' == $prop->modification) { $value = $element->getValue(); echo $this->_config->fieldTranform($elementid, $value); echo "<input id='{$elementid}' name='{$elementid}' type='hidden' value='{$value}'>"; } else { echo $element; } } else { echo $element; } ?> </div> </div> <?php } ?> </fieldset> <?php $index += 1; } ?> </form> <?php $this->view->jQuery()->onLoadCaptureStart(); ?> $('form#<?php echo $this->_form_id; ?> ').find('dt').remove(); $('#SaveButton').unbind().bind('click',function(){ $('form#<?php echo $this->_form_id; ?> ').submit(); }); <?php $this->view->jQuery()->onLoadCaptureEnd(); ?> <?php }
protected function _submitForm(App_Form $form, $request, $id = '') { //print_r($_POST); //$form = new App_Form_Table($this->_modelName); //$this->_setForm ( $form,$this->_model ); $id = trim($id); if ($request->getPost()) { if ($form->isValid($request->getPost())) { $isValid = true; if ($isValid) { try { if ($id == null) { $info = 7; } else { $info = 8; } $lastId = $form->save($id); $data['id'] = $lastId; if ($form->isInsearted()) { //echo "isInsearted"; //$this->_callBackAffterInsert ( $form, $data ); } elseif ($form->isUpdated()) { //$this->_callBackAffterUpdate ( $form, $data ); } if (trim($id) == '') { $id = $lastId; } return true; //$this->view->alert("กรุณากรอกข้อมูลในแบบฟอร์มให้ถูกต้อง และ บันทึกข้อมูลอีกครั้ง"); // $this->view->infocode = $info; } catch (Exception $e) { $this->view->alert("เกิดปัญหาในการบันทึกข้อมูล ลองบันทึกข้อมูลอีกครั้ง"); $this->view->infocode = App_Env::sqlerror($e->getMessage()); return false; } } } else { $errors = $form->getMessages(); $messages = array(); foreach ($errors as $element_name => $error) { $element_messages = array(); foreach ($error as $elmessages) { $element_messages[] = "{$elmessages}"; } $messages[] = "{$element_name}:" . join(",", $element_messages); } $form_alert_message = join("<br/>", $messages); $this->view->alert("กรุณากรอกข้อมูลในแบบฟอร์มให้ถูกต้อง และ บันทึกข้อมูลอีกครั้ง <br/>" . str_replace("'", "\\'", $form_alert_message)); return false; } } else { return false; // $this->view->infocode = "no post data"; } return false; }
/** * Create Modal dialog business logic * @param App_Form $form * @param array $options */ public function ajaxFormProcessor(App_Form $form, $options) { $params = $this->_getAllParams(); $subaction = isset($params['subaction']) ? $params['subaction'] : null; switch ($subaction) { case 'submit': if (!$form->isValid($params)) { $this->view->isValid = $form->isValid($params); $this->view->message = $form->getErrorMessages(); } else { $this->view->isValid = $form->isValid($params); $modelClass = $options['model']['class']; $modelMethod = $options['model']['method']; // persist method call_user_func(array($modelClass, $modelMethod), $params); $this->setMessage(self::$_translate->_($options['success']['message'])); $this->createAjaxButton($options['success']['button']['title'], $options['success']['button']['action']); if (isset($options['success']['redirect'])) { $this->view->redirect = $this->baseUrl . $options['success']['redirect']; } break; } default: $this->view->title = self::$_translate->_($options['title']); $this->createAjaxButton(self::$_translate->_($options['button']), "submit", $params, $options['url']); $this->view->form = $form->toArray(); } }
public function init() { parent::init(); }