示例#1
0
 /**
  * A central place to render global errors for both BaseFormPropel subclasses, and mySfForm subclasses.
  * Works in conjunction with hasGlobalErrors above.
  * @param sfForm $form
  * @return string The errors, formatted appropriately.
  */
 public static function renderGlobalErrors($form)
 {
     //$globalErrorsText = parent::renderGlobalErrors();
     $globalErrorsText = '';
     //treat any error as a global error.
     $nonGlobalErrors = $form->getErrorSchema()->getErrors();
     $nonGlobalErrorCount = count($nonGlobalErrors);
     if ($nonGlobalErrorCount > 0) {
         //$globalErrorsText .= '(1) ';//<br />The following fields are required: ';
         $count = 1;
         ////print_r($nonGlobalErrors);
         foreach ($nonGlobalErrors as $key => $nonGlobalError) {
             //$globalErrorsText .= '<br />'.$key . ': ' . $nonGlobalError->getMessage() . '<br />';
             $labelName = '';
             if (isset($form[$key])) {
                 $labelName = $form[$key]->renderLabelName();
             }
             $globalErrorsText .= $labelName . ': ' . $nonGlobalError . ' ';
             //put a comma after each if it isn't the last, otherwise a full stop.
             if ($count < $nonGlobalErrorCount) {
                 //$globalErrorsText .= sprintf(" (%s) ", $count+1);
             } else {
                 $globalErrorsText .= ".";
             }
             $count++;
         }
     }
     return $globalErrorsText;
 }
 /**
  * @see sfWebRequest
  */
 public function checkCSRFProtection()
 {
     try {
         parent::checkCSRFProtection();
     } catch (sfValidatorErrorSchema $e) {
         // retry checking for using sfForm (just for BC)
         $form = new sfForm();
         $form->bind($form->isCSRFProtected() ? array($form->getCSRFFieldName() => $this->getParameter($form->getCSRFFieldName())) : array());
         if (!$form->isValid()) {
             throw $form->getErrorSchema();
         }
     }
 }
示例#3
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         try {
             $item = $form->save();
             $this->redirect('loanitem/edit?id=' . $item->getId());
         } catch (Doctrine_Exception $ne) {
             $e = new DarwinPgErrorParser($ne);
             $error = new sfValidatorError(new savedValidator(), $e->getMessage());
             $form->getErrorSchema()->addError($error);
         }
     }
 }
 /** Return additional failure description where needed
  *
  * The function can be overritten to provide additional failure information
  *  like a diff
  *
  * @param  sfForm $form Evaluated value or object.
  * @return string
  */
 protected function additionalFailureDescription($form)
 {
     /* If the form has errors, add them to the message, since that's what we're
      *  going to be interested in when the assertion fails).
      *
      * Note that we only have to check for this if we were expecting the form to
      *  be valid (give it a second; it'll come to you).
      */
     if ($this->_expected and $errors = $form->getErrorSchema()->getErrors()) {
         return sprintf('Form has errors:%s%s', PHP_EOL, print_r(array_map('strval', $errors), true));
     }
     return '';
 }
 protected function processForm(sfForm $form, $data = array())
 {
     $form->bind($data);
     if ($form->isValid()) {
         try {
             $report = $form->save();
             return $report;
         } catch (Doctrine_Validator_Exception $e) {
             $errorStack = $form->getObject()->getErrorStack();
             $message = get_class($form->getObject()) . ' has ' . count($errorStack) . " field" . (count($errorStack) > 1 ? 's' : null) . " with validation errors: ";
             foreach ($errorStack as $field => $errors) {
                 $message .= "{$field} (" . implode(", ", $errors) . "), ";
             }
             $message = trim($message, ', ');
             throw new sfException($message);
         }
     } else {
         if ($es = $form->getErrorSchema()) {
             throw new sfException($es->getMessage());
         }
         throw new sfException('The item has not been saved due to some errors.');
     }
 }
示例#6
0
 protected function processJsonForm(sfWebRequest $request, sfForm $form, $form_data = null)
 {
     $params = (array) json_decode($request->getParameter($form->getName()));
     if (!$form_data) {
         $form_data = $params;
     }
     $form->bind($form_data);
     //$form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     //$params = $request->getParameter($form->getName());
     if ($form->isValid()) {
         try {
             $etva_node = $form->save();
             $uuid = $etva_node->getUuid();
             $result = array('success' => true, 'uuid' => $uuid, 'keepalive_update' => sfConfig::get('app_node_keepalive_update'), 'object' => $etva_node);
             //notify system log
             $message = Etva::getLogMessage(array('name' => $etva_node->getName(), 'uuid' => $uuid, 'keepalive_update' => $result['keepalive_update']), EtvaNodePeer::_OK_SOAPINIT_);
             $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::INFO)));
         } catch (Exception $e) {
             $result = array('success' => false, 'error' => array('node' => $e->getMessage()), 'obj' => $etva_node);
         }
         return $result;
     } else {
         $errors = array();
         foreach ($form->getErrorSchema() as $field => $error) {
             $errors[$field] = $error->getMessage();
         }
         $result = array('success' => false, 'error' => $errors);
         //notify system log
         $message = Etva::getLogMessage(array('name' => $params['name'], 'uuid' => $params['uuid']), EtvaNodePeer::_ERR_SOAPINIT_);
         $this->dispatcher->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         return $result;
     }
 }
 /**
  * Собирает в строку сообщения об ошибках
  *
  * @param  sfForm $form
  * @param  array  $errors
  * @return string
  */
 protected function formatErrorMessage(sfForm $form, array $errors)
 {
     return ($errors ? "[Invalid.] " . implode(" [Invalid.] ", $errors) : "") . (strlen($form->getErrorSchema()) ? ($errors ? " " : "") . $form->getErrorSchema() : "");
 }
 public function checkCSRFProtection()
 {
     $form = new sfForm();
     $form->bind($form->isCSRFProtected() ? array($form->getCSRFFieldName() => $this->getParameter($form->getCSRFFieldName())) : array());
     if (!$form->isValid()) {
         throw $form->getErrorSchema();
     }
 }
示例#9
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $updated = $form->getObject()->isNew() ? 'created' : 'updated';
         $invoice = $form->save();
         // update totals with saved values
         $invoice->refresh(true)->setAmounts()->save();
         $this->getUser()->info("The recurring invoice was {$updated} successfully.");
         $this->redirect('recurring/edit?id=' . $invoice->id);
     } else {
         foreach ($form->getErrorSchema()->getErrors() as $k => $v) {
             $this->getUser()->error(sprintf('%s: %s', $k, $v->getMessageFormat()));
         }
         $this->getUser()->error('The recurring invoice has not been saved due to some errors.');
     }
 }
示例#10
0
 protected function processForm(sfWebRequest $request, sfForm $form, $action = 'create')
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         try {
             $wasNew = $form->isNew();
             $autoCodeForUpdate = false;
             if (!$wasNew) {
                 $collection = Doctrine::getTable('Collections')->findOneById($form->getObject()->getCollectionRef());
                 $autoCodeForUpdate = !$collection->getCodeAutoIncrementForInsertOnly();
             }
             $specimen = $form->save();
             if ($wasNew || $autoCodeForUpdate) {
                 Doctrine::getTable('Collections')->afterSaveAddCode($specimen->getCollectionRef(), $specimen->getId());
             }
             $this->redirect('specimen/edit?id=' . $specimen->getId());
         } catch (Doctrine_Exception $ne) {
             if ($action == 'create') {
                 //If Problem in saving embed forms set dirty state
                 $form->getObject()->state('TDIRTY');
             }
             $e = new DarwinPgErrorParser($ne);
             $extd_message = '';
             if (preg_match('/unique constraint "unq_specimens"/i', $ne->getMessage())) {
                 $dup_spec = Doctrine::getTable('Specimens')->findDuplicate($form->getObject());
                 if (!$dup_spec) {
                     $this->logMessage('Duplicate Specimen not found: ' . json_encode($form->getObject()->toArray()), 'err');
                 } else {
                     $extd_message = '<br /><a href="' . $this->getController()->genUrl('specimen/edit?id=' . $dup_spec->getId()) . '">' . $this->getI18N()->__('Go the the original record') . '</a>';
                 }
             }
             $error = new sfValidatorError(new savedValidator(), $e->getMessage() . $extd_message);
             $form->getErrorSchema()->addError($error, 'Darwin2 :');
         }
     }
 }
示例#11
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $isNew = $this->ei_block_param->isNew();
         $this->ei_block_param = $form->save();
         if ($isNew) {
             $this->ei_block_param->getNode()->insertAsLastChildOf($this->ei_block_parent);
         }
         return false;
     } else {
         $JSONResponse['status'] = "error";
         $errors = $form->getErrorSchema()->getErrors();
         $JSONResponse['message'] = "Unable to save the parameter. " . $errors['name'];
     }
     return $JSONResponse;
 }
 protected function getErrores(sfForm $form)
 {
     #$fields = $form->getWidgetSchema()->getFields();
     $oParcial = $form->getErrorSchema()->getNamedErrors();
     $aParcial = array();
     $oGlobal = $form->getErrorSchema()->getGlobalErrors();
     $aGlobal = array();
     #$form_name = $form->getName();
     foreach ($oParcial as $n => $e) {
         #if(!$form->offsetExists($n) || $fields[$n]->isHidden())
         #	$aGlobal[$form_name.'_global_error'] = $e->getMessage();
         #else
         #	$aParcial[$form_name.'_'.$n.'_error'] = $e->getMessage();
         return $e->getMessage();
     }
     foreach ($oGlobal as $n => $e) {
         #$aGlobal[$form_name.'_global_error'] = $e->getMessage();
         return $e->getMessage();
     }
     #$errors = array_merge($aParcial, $aGlobal);
     #return $errors;
 }
示例#13
0
 protected function processForm(sfWebRequest $request, sfForm $form, $celulaId = null)
 {
     $asistencia = $request->getParameter('reunion')['asistencias'];
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     $fields = $form->getFormFieldSchema()->getValue();
     if ($form->isValid()) {
         $reunion = $form->save();
         foreach ($reunion->getAsistencias() as $borrable) {
             $borrable->delete();
         }
         $asistencias = explode(',', $asistencia);
         foreach ($asistencias as $key => $asistencia) {
             if ($asistencia > 0) {
                 $source = new Asistencia();
                 $source->setReunionId($reunion->getId());
                 $source->setMiembroCelulaId($asistencia);
                 $source->save();
             }
         }
         $this->getUser()->setFlash('notice', "Reunión guardada exitosamente", true);
         if (isset($celulaId)) {
             $this->redirect('celulas/show?id=' . $celulaId);
         } else {
             $this->forward('celulas', 'index');
         }
     }
     $this->getUser()->setFlash('error', "Error!!! " . $form->getErrorSchema(), true);
     if (isset($celulaId)) {
         $this->redirect('celulas/show?id=' . $celulaId);
     } else {
         $this->forward('celulas', 'index');
     }
 }
示例#14
0
 protected function processJsonForm(sfWebRequest $request, sfForm $form, $form_data = null)
 {
     if (!$form_data) {
         $form_data = (array) json_decode($request->getParameter($form->getName()));
     }
     $form->bind($form_data);
     if ($form->isValid()) {
         // if default cluster changed
         if ($form_data['isDefaultCluster']) {
             $updatecluster = array('Isdefaultcluster' => 0);
             EtvaClusterQuery::create()->update($updatecluster);
         }
         try {
             $etva_cluster = $form->save();
             $result = array('success' => true, 'object' => $etva_cluster);
         } catch (Exception $e) {
             $result = array('success' => false, 'error' => array('cluster' => $e->getMessage()), 'obj' => $etva_cluster);
             return $result;
         }
         return $result;
     } else {
         $errors = array();
         foreach ($form->getErrorSchema() as $field => $error) {
             $errors[$field] = $error->getMessage();
         }
         //notify system log
         $msg_i18n = Etva::makeNotifyLogMessage(sfConfig::get('config_acronym'), EtvaClusterPeer::_ERR_UPDATE_, array('name' => $form_data['name'], 'info' => $this->setJsonError($errors)));
         $result = array('success' => false, 'error' => $msg_i18n, 'info' => $msg_i18n);
         return $result;
     }
 }
示例#15
0
 /**     
  *
  * process server form data. binds request data with form and save
  *
  * @param sfWebRequest $request A request object
  * @param sfForm $form A form object
  *
  */
 protected function processJsonForm(sfWebRequest $request, sfForm $form)
 {
     // get submitted form elements
     $form_elems = $request->getParameter($form->getName());
     // retrieve mac pool elements number
     // $mac_pool = $request->getParameter('mac_pool');
     //generate random macs and add to form elements
     //    if(isset($mac_pool)){
     //        $macs = $this->generateMacPool($mac_pool);
     //        $macs = implode(',',$macs);
     //
     //        $form_elems['mac_addresses'] = $macs;
     //    }
     $form->bind($form_elems, $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $etva_server = $form->save();
         //$result = array('success'=>true,'insert_id'=>$etva_server->getId());
         $result = array('success' => true, 'object' => $etva_server->toArray());
         return $result;
     } else {
         $errors = array();
         foreach ($form->getErrorSchema() as $field => $error) {
             $errors[$field] = $error->getMessage();
         }
         $result = array('success' => false, 'error' => $errors);
         return $result;
     }
 }
示例#16
0
 protected function processForm(sfWebRequest $request, sfForm $form, $action = 'create')
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         try {
             $item = $form->save();
             $this->redirect('gtu/edit?id=' . $item->getId());
         } catch (Doctrine_Exception $ne) {
             if ($action == 'create') {
                 //If Problem in saving embed forms set dirty state
                 $form->getObject()->state('TDIRTY');
             }
             $e = new DarwinPgErrorParser($ne);
             $error = new sfValidatorError(new savedValidator(), $e->getMessage());
             $form->getErrorSchema()->addError($error);
         }
     }
 }
示例#17
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $this->getResponse()->setContentType('application/json');
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $isNew = $this->ei_block->isNew();
         $this->ei_block = $form->save();
         if ($isNew && !$this->isFull) {
             if ($this->insert_after) {
                 $this->ei_block->getNode()->insertAsNextSiblingOf($this->ei_block_parent);
             } else {
                 $this->ei_block->getNode()->insertAsFirstChildOf($this->ei_block_parent);
             }
         } elseif ($isNew && $this->isFull && $this->ei_vs_precedent != null) {
             $this->ei_block->getNode()->insertAsNextSiblingOf($this->ei_vs_precedent);
         } elseif ($isNew && $this->isFull && $this->ei_block_parent != null && $this->ei_vs_precedent == null) {
             $this->ei_block->getNode()->insertAsFirstChildOf($this->ei_block_parent);
         }
         if ($isNew && $this->isFull && array_key_exists("EiBlockParams", $form->getEmbeddedForms()) && !$this->ei_block->isEiLoop()) {
             $forms = $form->getEmbeddedForm("EiBlockParams")->getEmbeddedForms();
             $prev = null;
             /** @var EiBlockParamForm $form */
             foreach ($forms as $form) {
                 if ($prev == null) {
                     $form->getObject()->getNode()->insertAsLastChildOf($this->ei_block);
                 } else {
                     $form->getObject()->getNode()->insertAsNextSiblingOf($prev);
                 }
                 $prev = $form->getObject();
             }
         } elseif ($isNew && $this->isFull && $this->ei_block->isEiLoop()) {
             $this->ei_block->createAutoMapping();
         } elseif (!$isNew && $this->isFull && array_key_exists("EiBlockParams", $form->getEmbeddedForms())) {
             $forms = $form->getEmbeddedForm("EiBlockParams")->getEmbeddedForms();
             $prev = null;
             $nouvelleCollection = array();
             /** @var EiBlockParamForm $form */
             foreach ($forms as $form) {
                 $nouvelleCollection[] = $form->getObject()->getId();
                 if ($prev == null && $form->getObject()->getLft() == null) {
                     $form->getObject()->getNode()->insertAsLastChildOf($this->ei_block);
                 } elseif ($form->getObject()->getLft() == null) {
                     $form->getObject()->getNode()->insertAsNextSiblingOf($prev);
                 }
                 $prev = $form->getObject();
             }
             foreach ($this->ei_block->getEiVersionStructures() as $key => $structureElt) {
                 if ($structureElt instanceof EiBlockParam && !in_array($structureElt->getId(), $nouvelleCollection)) {
                     $this->ei_block->getEiVersionStructures()->remove($key);
                 }
             }
             $this->ei_block->save();
         }
         return false;
     } else {
         $JSONResponse['status'] = "error";
         $errors = $form->getErrorSchema()->getErrors();
         if (isset($errors["name"])) {
             $nomErreur = $errors["name"];
         } else {
             $nomErreur = "";
         }
         $JSONResponse['message'] = "Unable to save the block. " . $nomErreur;
     }
     return $JSONResponse;
 }
示例#18
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $i18n = $this->getContext()->getI18N();
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $template = 'The customer was %s successfully %s.';
         $message = $form->getObject()->isNew() ? 'created' : 'updated';
         $suffix = null;
         $method = 'info';
         $customer = $form->save();
         $this->getUser()->{$method}($i18n->__(sprintf($template, $message, $suffix)));
         $this->redirect('customers/edit?id=' . $customer->id);
     } else {
         foreach ($form->getErrorSchema()->getErrors() as $k => $v) {
             $this->getUser()->error(sprintf('%s: %s', $k, $v->getMessageFormat()));
         }
         $this->getUser()->error($i18n->__('The customer has not been saved due to some errors.'));
     }
 }
示例#19
0
 /**
  * Method called to process the encoding form (called by executeCreate or executeUpdate actions)
  * @param sfWebRequest $request Request coming from browser
  * @param sfForm       $form    The encoding form passed to be bound with data brought by the request and to be checked
  * @var   sfForm       $igs: Form saved
  */
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()));
     if ($form->isValid()) {
         try {
             $igs = $form->save();
             $this->redirect('igs/edit?id=' . $igs->getId());
         } catch (Doctrine_Exception $ne) {
             $e = new DarwinPgErrorParser($ne);
             $extd_message = '';
             if (preg_match('/unique constraint "unq_igs"/i', $ne->getMessage())) {
                 $dup_igs = Doctrine::getTable('Igs')->findDuplicate($form->getObject());
                 if (!$dup_igs) {
                     $this->logMessage('Duplicate Igs not found: ' . json_encode($form->getObject()->toArray()), 'err');
                 } else {
                     $extd_message = '<br /><a href="' . $this->getController()->genUrl('igs/edit?id=' . $dup_igs->getId()) . '">' . $this->getI18N()->__('Go the the original record') . '</a>';
                 }
                 $error = new sfValidatorError(new savedValidator(), $e->getMessage() . $extd_message);
                 $form->getErrorSchema()->addError($error);
             } else {
                 $this->logMessage('Undef igs Error : ' . $ne->getMessage(), 'err');
                 $error = new sfValidatorError(new savedValidator(), 'Undefined Error');
                 $form->getErrorSchema()->addError($error);
             }
         }
     }
 }
 /**
  * Make error messge
  *
  * Display incoming data and errors list
  *
  * @param sfForm $form
  * @param string $message
  */
 protected function makeErrorMess(sfForm $form, $message)
 {
     return sprintf("%s\n\nErrors: %s\n\nInput:\n%s", $message, $form->getErrorSchema(), var_export($form->getTaintedValues(), true));
 }
示例#21
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     if ($this->getUser()->isA(Users::REGISTERED_USER)) {
         $this->forwardToSecureAction();
     }
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         try {
             $form->save();
             $this->redirect('taxonomy/edit?id=' . $form->getObject()->getId());
         } catch (Doctrine_Exception $ne) {
             $e = new DarwinPgErrorParser($ne);
             $error = new sfValidatorError(new savedValidator(), $e->getMessage());
             $form->getErrorSchema()->addError($error);
         }
     }
 }
示例#22
0
 protected function processForm(sfWebRequest $request, sfForm $form, array $fields)
 {
     $form->bind($request->getParameter($form->getName()));
     if ($form->isValid()) {
         try {
             $form->save();
             return $this->redirect('staging/index?import=' . $form->getObject()->getImportRef());
         } catch (Doctrine_Exception $ne) {
             $e = new DarwinPgErrorParser($ne);
             $error = new sfValidatorError(new savedValidator(), $e->getMessage());
             $form->getErrorSchema()->addError($error);
         }
     }
 }
示例#23
0
 protected function processNodeForm($data, sfForm $form)
 {
     $uuid = $data['uuid'];
     $form->bind($data);
     if ($form->isValid()) {
         $etva_node = $form->save();
         $uuid = $etva_node->getUuid();
         $result = array('success' => true, 'uuid' => $uuid, 'keepalive_update' => sfConfig::get('app_node_keepalive_update'), 'state' => $etva_node->getState());
         if ($data['initialize'] == self::INITIALIZE_PENDING) {
             $msg_type = EtvaNodePeer::_OK_SOAPREGISTER_;
         } else {
             $msg_type = EtvaNodePeer::_OK_SOAPINIT_;
         }
         //notify system log
         $message = Etva::getLogMessage(array('name' => $etva_node->getName(), 'uuid' => $uuid, 'keepalive_update' => $result['keepalive_update']), $msg_type);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::INFO)));
         return $result;
     } else {
         $errors = array();
         foreach ($form->getErrorSchema() as $field => $error) {
             $errors[$field] = $error->getMessage();
         }
         $result = array('success' => false, 'error' => $errors);
         //notify system log
         $message = Etva::getLogMessage(array('name' => $data['name'], 'uuid' => $uuid), EtvaNodePeer::_ERR_SOAPINIT_);
         sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(sfConfig::get('config_acronym'), 'event.log', array('message' => $message, 'priority' => EtvaEventLogger::ERR)));
         return $result;
     }
 }
示例#24
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()));
     if ($form->isValid()) {
         try {
             $collections = $form->save();
             $this->redirect('collection/edit?id=' . $collections->getId());
         } catch (Exception $e) {
             $error = new sfValidatorError(new savedValidator(), $e->getMessage());
             $form->getErrorSchema()->addError($error);
         }
     }
 }
示例#25
0
 protected function processForm(sfWebRequest $request, sfForm $form)
 {
     $i18n = $this->getContext()->getI18N();
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $estimate = $form->save();
         // update totals with saved values
         $estimate->refresh(true)->setAmounts()->save();
         if ($request->getParameter('send_email')) {
             if ($this->sendEmail($estimate)) {
                 $this->getUser()->info($i18n->__('The estimate was successfully sent.'));
             } else {
                 $this->getUser()->warn($i18n->__('The estimate could not be sent due to an error.'));
             }
         }
         if ($request->getParameter('generate_invoice')) {
             if ($estimate->generateInvoice()) {
                 $this->getUser()->info($i18n->__('The invoice was successfully created.'));
             } else {
                 $this->getUser()->warn($i18n->__('The invoice could not be created due to an error.'));
             }
         }
         $this->getUser()->info($i18n->__('The estimate was successfully saved.'));
         $this->redirect('estimates/edit?id=' . $estimate->id);
     } else {
         foreach ($form->getErrorSchema()->getErrors() as $k => $v) {
             $this->getUser()->error(sprintf('%s: %s', $k, $v->getMessageFormat()));
         }
         $this->getUser()->error($i18n->__('The estimate has not been saved due to some errors.'));
     }
 }
示例#26
0
 protected function processJsonForm(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $etva_network = $form->save();
         $result = array('success' => true, 'insert_id' => $etva_network->getId());
         return $result;
     } else {
         $errors = array();
         foreach ($form->getErrorSchema() as $field => $error) {
             $errors[$field] = $error->getMessage();
         }
         $result = array('success' => false, 'error' => $errors);
         return $result;
     }
 }
示例#27
0
 /**
  * @param sfWebRequest $request
  * @param sfForm $form
  */
 private function processFormLeaf(sfWebRequest $request, sfForm $form)
 {
     $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
     if ($form->isValid()) {
         $new = $this->ei_leaf->isNew();
         // On sauvegarde le formulaire.
         $this->ei_leaf = $form->save();
         if ($new && $this->ei_node != null) {
             // Puis on place le noeud dans l'arbre.
             $this->ei_leaf->getNode()->insertAsFirstChildOf($this->ei_node);
         }
         return false;
     } else {
         $errors = $form->getErrorSchema()->getErrors();
         if (isset($errors["name"])) {
             $nomErreur = $errors["name"];
         } else {
             $nomErreur = "";
         }
         return $this->createJSONResponse("created", "error", "Leaf", "Unable to save the node. " . $nomErreur);
     }
 }