public function process_response($SubmittedForm) { $opts = $this->_load_options(); $data = array(); $data['fields'] = array(); $data['files'] = array(); $data['page'] = $SubmittedForm->page; if (class_exists('PerchContent_Pages')) { $Pages = new PerchContent_Pages(); $Page = $Pages->find_by_path($SubmittedForm->page); if ($Page) { $data['page'] = array('id' => $Page->pageID(), 'title' => $Page->pageTitle(), 'path' => $Page->pagePath(), 'navtext' => $Page->pageNavText()); } } // Anti-spam $spam = false; $antispam = $SubmittedForm->get_antispam_values(); $environment = $_SERVER; $akismetAPIKey = false; if (isset($opts->akismet) && $opts->akismet) { if (isset($opts->akismetAPIKey) && $opts->akismetAPIKey != '') { $akismetAPIKey = $opts->akismetAPIKey; } } $spam = $this->_check_for_spam($antispam, $environment, $akismetAPIKey); // Files if (!$spam && PerchUtil::count($SubmittedForm->files)) { if (isset($opts->fileLocation) && $opts->fileLocation != '') { foreach ($SubmittedForm->files as $key => &$details) { if ($details['error'] == '0' && $details['size'] > 0) { // no error, upload worked $attrs = $SubmittedForm->get_template_attributes($key); if (is_uploaded_file($details['tmp_name'])) { $filename = $details['name']; $dest = rtrim($opts->fileLocation, '\\/') . DIRECTORY_SEPARATOR; if (file_exists($dest . $filename)) { $filename = time() . $filename; } if (file_exists($dest . $filename)) { $filename = time() . mt_rand() . $filename; } if (PerchUtil::move_uploaded_file($details['tmp_name'], $dest . $filename)) { $details['new_path'] = $dest . $filename; $details['new_filename'] = $filename; $file = new stdClass(); $file->name = $filename; $file->path = $dest . $filename; $file->size = $details['size']; $file->mime = ''; if (isset($SubmittedForm->mimetypes[$key])) { $file->mime = $SubmittedForm->mimetypes[$key]; } $file->attributes = $attrs->get_attributes(); $data['files'][$key] = $file; } } } } } else { PerchUtil::debug('Form ' . $SubmittedForm->id . ': File save location not set, files discarded.', 'error'); } } // Fields if (PerchUtil::count($SubmittedForm->data)) { foreach ($SubmittedForm->data as $key => $value) { $attrs = $SubmittedForm->get_template_attributes($key); if ($attrs) { $field = new stdClass(); $field->attributes = $attrs->get_attributes(); // skip submit fields if (isset($field->attributes['type']) && $field->attributes['type'] == 'submit') { // skip it. } else { // skip honeypot field if (isset($field->attributes['antispam']) && $field->attributes['antispam'] == 'honeypot') { // skip it } else { $field->value = $value; $data['fields'][$attrs->id()] = $field; } } } } } if (!$spam && isset($opts->email) && $opts->email) { $this->_send_email($opts, $data); } if (isset($opts->store) && $opts->store) { $json = PerchUtil::json_safe_encode($data); $record = array(); $record['responseJSON'] = $json; $record['formID'] = $this->id(); $record['responseIP'] = $_SERVER['REMOTE_ADDR']; if ($spam) { $record['responseSpam'] = '1'; } $spam_data = array(); $spam_data['fields'] = $antispam; $spam_data['environment'] = $environment; $record['responseSpamData'] = PerchUtil::json_safe_encode($spam_data); $Responses = new PerchForms_Responses($this->api); $Response = $Responses->create($record); } if ($spam || !isset($opts->store) || !$opts->store) { // not storing, so drop files if (PerchUtil::count($data['files'])) { foreach ($data['files'] as $file) { if (file_exists($file->path)) { @unlink($file->path); } } } } // Redirect? if (isset($opts->successURL) && $opts->successURL) { PerchUtil::redirect(trim($opts->successURL)); } }