/**
  * @param SubmissionProcessedEvent $event
  */
 public function onSubmissionProcessed(SubmissionProcessedEvent $event)
 {
     $submission = $event->getSubmission();
     $form = $submission->getForm();
     $tplFile = $form->getCacheDir() . '/receipt.tpl';
     if (!file_exists($tplFile)) {
         return;
     }
     $fh = fopen($tplFile, 'r');
     $subject = fgets($fh);
     $from = fgets($fh);
     $tpl = '';
     while (($line = fgets($fh)) !== false) {
         $tpl .= $line;
     }
     fclose($fh);
     $data = $submission->getData();
     if (!isset($data['email'])) {
         return;
     }
     $email = $data['email'];
     foreach ($data as $key => $value) {
         $tpl = str_replace("%{$key}%", $value, $tpl);
     }
     // send email to submitter
     mail($email, $subject, $tpl, 'From: ' . $from);
 }
Esempio n. 2
0
 /**
  * @param SubmissionProcessedEvent $event
  */
 public function onSubmissionProcessed(SubmissionProcessedEvent $event)
 {
     $submission = $event->getSubmission();
     $form = $submission->getForm();
     $body = 'Submitted via ' . $form->getUrl() . "\n\n";
     foreach ($submission->getData() as $key => $value) {
         $body .= $form->getFieldTitle($key) . ":\n{$value}\n\n";
     }
     // send emails to listed recipients
     foreach ($this->emails as $addr) {
         mail($addr, 'ninja: ' . $form->getUrl(), $body);
     }
 }
Esempio n. 3
0
 /**
  * @param SubmissionProcessedEvent $event
  */
 public function onSubmissionProcessed(SubmissionProcessedEvent $event)
 {
     $submission = $event->getSubmission();
     $form = $submission->getForm();
     $saveFile = $form->getCacheDir() . '/submissions.tsv';
     // get formatted row
     $fields = $form->getFields();
     if (!file_exists($saveFile)) {
         $headings = implode("\t", array_values($fields)) . "\n";
         file_put_contents($saveFile, $headings);
     }
     $row = [];
     $data = $submission->getData();
     foreach (array_keys($fields) as $key) {
         $row[] = $data[$key];
     }
     // write row to file
     file_put_contents($saveFile, implode("\t", $row) . "\n", FILE_APPEND);
 }
Esempio n. 4
0
 public static function onSubmissionProcessedEvent(SubmissionProcessedEvent $e)
 {
     $submission = $e->getSubmission();
     $form = $submission->getForm();
     return 'processed submission (' . $submission->getId() . ') from [' . $form->getUrl() . '] (' . $form->getId() . ')';
 }