public function submit($id = null)
 {
     $r = $this->entityManager->getRepository('\\Concrete\\Core\\Entity\\Express\\Entity');
     $entity = $r->findOneById($id);
     $r = $this->entityManager->getRepository('\\Concrete\\Core\\Entity\\Express\\Form');
     $form = $r->findOneById($this->request->request->get('express_form_id'));
     $entry = null;
     if ($this->request->request->has('entry_id')) {
         $entry = $this->entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Entry')->findOneById($this->request->request->get('entry_id'));
     }
     if ($entry === null) {
         $permissions = new \Permissions($entity);
         if (!$permissions->canAddExpressEntries()) {
             $this->error->add(t('You do not have access to add entries of this entity type.'));
         }
     } else {
         $permissions = new \Permissions($entry);
         if (!$permissions->canEditExpressEntry()) {
             $this->error->add(t('You do not have access to edit entries of this entity type.'));
         }
     }
     if ($form !== null) {
         $validator = new Validator($this->error, $this->request);
         $validator->validate($form);
         if (!$this->error->has()) {
             $manager = new Manager($this->entityManager, $this->request);
             if ($entry === null) {
                 // create
                 $entry = $manager->addEntry($entity);
                 $manager->saveEntryAttributesForm($form, $entry);
                 $this->flash('success', tc('Express', 'New record %s added successfully.', $entity->getName()) . '<br />' . '<a class="btn btn-default" href="' . \URL::to(\Page::getCurrentPage(), 'view_entry', $entry->getID()) . '">' . t('View Record Here') . '</a>', true);
                 $this->redirect(\URL::to(\Page::getCurrentPage(), 'create_entry', $entity->getID()));
             } else {
                 // update
                 $manager->saveEntryAttributesForm($form, $entry);
                 $this->flash('success', t('%s updated successfully.', $entity->getName()));
                 $this->redirect($this->getBackURL($entity));
             }
         }
     } else {
         throw new \Exception(t('Invalid form.'));
     }
 }
コード例 #2
0
 public function action_submit($bID = null)
 {
     if ($this->bID == $bID) {
         $entityManager = \Core::make('database/orm')->entityManager();
         $form = $this->getFormEntity();
         if (is_object($form)) {
             $e = \Core::make('error');
             $validator = new Validator($e, $this->request);
             $validator->validate($form);
             if ($this->displayCaptcha) {
                 $captcha = \Core::make('helper/validation/captcha');
                 if (!$captcha->check()) {
                     $e->add(t('Incorrect captcha code.'));
                 }
             }
             $this->set('error', $e);
         }
         $entity = $form->getEntity();
         $permissions = new \Permissions($entity);
         if (!$permissions->canAddExpressEntries()) {
             $e->add(t('You do not have access to submit this form.'));
         }
         if (isset($e) && !$e->has()) {
             $manager = new Manager($entityManager, $this->request);
             $entry = $manager->addEntry($entity);
             $entry = $manager->saveEntryAttributesForm($form, $entry);
             $values = $entity->getAttributeKeyCategory()->getAttributeValues($entry);
             // Check antispam
             $antispam = \Core::make('helper/validation/antispam');
             $submittedData = '';
             foreach ($values as $value) {
                 $submittedData .= $value->getAttributeKey()->getAttributeKeyDisplayName() . ":\r\n";
                 $submittedData .= $value->getPlainTextValue() . "\r\n\r\n";
             }
             if (!$antispam->check($submittedData, 'form_block')) {
                 // Remove the entry and silently fail.
                 $entityManager->refresh($entry);
                 $entityManager->remove($entry);
                 $entityManager->flush();
                 $c = \Page::getCurrentPage();
                 $r = Redirect::page($c);
                 $r->setTargetUrl($r->getTargetUrl() . '#form' . $this->bID);
                 return $r;
             }
             if ($this->addFilesToSet) {
                 $set = Set::getByID($this->addFilesToSet);
                 if (is_object($set)) {
                     foreach ($values as $value) {
                         $value = $value->getValueObject();
                         if ($value instanceof FileProviderInterface) {
                             $files = $value->getFileObjects();
                             foreach ($files as $file) {
                                 $set->addFileToSet($file);
                             }
                         }
                     }
                 }
             }
             if ($this->notifyMeOnSubmission) {
                 if (\Config::get('concrete.email.form_block.address') && strstr(\Config::get('concrete.email.form_block.address'), '@')) {
                     $formFormEmailAddress = \Config::get('concrete.email.form_block.address');
                 } else {
                     $adminUserInfo = \UserInfo::getByID(USER_SUPER_ID);
                     $formFormEmailAddress = $adminUserInfo->getUserEmail();
                 }
                 $replyToEmailAddress = $formFormEmailAddress;
                 if ($this->replyToEmailControlID) {
                     $control = $entityManager->getRepository('Concrete\\Core\\Entity\\Express\\Control\\Control')->findOneById($this->replyToEmailControlID);
                     if (is_object($control)) {
                         $email = $entry->getAttribute($control->getAttributeKey());
                         if ($email) {
                             $replyToEmailAddress = $email;
                         }
                     }
                 }
                 $formName = $this->getFormEntity()->getEntity()->getName();
                 $mh = \Core::make('helper/mail');
                 $mh->to($this->recipientEmail);
                 $mh->from($formFormEmailAddress);
                 $mh->replyto($replyToEmailAddress);
                 $mh->addParameter('entity', $entity);
                 $mh->addParameter('formName', $formName);
                 $mh->addParameter('attributes', $values);
                 $mh->load('block_express_form_submission');
                 $mh->setSubject(t('Website Form Submission – %s', $formName));
                 $mh->sendMail();
             }
             if ($this->redirectCID > 0) {
                 $c = \Page::getByID($this->redirectCID);
                 if (is_object($c) && !$c->isError()) {
                     $r = Redirect::page($c);
                     $r->setTargetUrl($r->getTargetUrl() . '?form_success=1');
                     return $r;
                 }
             }
             $c = \Page::getCurrentPage();
             $url = \URL::to($c, 'form_success', $this->bID);
             $r = Redirect::to($url);
             $r->setTargetUrl($r->getTargetUrl() . '#form' . $this->bID);
             return $r;
         }
     }
     $this->view();
 }