2008-09-29 05:18:23 +02:00
|
|
|
<?php
|
2010-07-07 11:17:37 +02:00
|
|
|
|
2017-08-09 01:55:09 +02:00
|
|
|
namespace SilverStripe\UserForms\Model;
|
|
|
|
|
|
|
|
use PageController;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Assets\File;
|
|
|
|
use SilverStripe\Assets\Upload;
|
|
|
|
use SilverStripe\Control\Controller;
|
2017-08-15 00:49:13 +02:00
|
|
|
use SilverStripe\Control\Email\Email;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Control\HTTP;
|
2017-08-13 23:26:53 +02:00
|
|
|
use SilverStripe\Core\Manifest\ModuleLoader;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\Forms\Form;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\i18n\i18n;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\ORM\ArrayList;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\ORM\FieldType\DBField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\ORM\ValidationException;
|
2017-08-15 00:49:13 +02:00
|
|
|
use SilverStripe\Security\Security;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\UserForms\Form\UserForm;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\UserForms\Model\EditableFormField\EditableFileField;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\UserForms\Model\Submission\SubmittedForm;
|
2017-08-09 01:55:09 +02:00
|
|
|
use SilverStripe\View\ArrayData;
|
2017-08-11 01:33:06 +02:00
|
|
|
use SilverStripe\View\Requirements;
|
|
|
|
use SilverStripe\View\SSViewer;
|
2017-08-09 01:55:09 +02:00
|
|
|
|
2008-09-29 05:18:23 +02:00
|
|
|
/**
|
|
|
|
* Controller for the {@link UserDefinedForm} page type.
|
2009-04-14 04:06:18 +02:00
|
|
|
*
|
2012-10-18 09:01:56 +02:00
|
|
|
* @package userforms
|
2008-09-29 05:18:23 +02:00
|
|
|
*/
|
2017-08-09 01:47:47 +02:00
|
|
|
class UserDefinedFormController extends PageController
|
2016-07-21 07:53:59 +02:00
|
|
|
{
|
|
|
|
private static $finished_anchor = '#uff';
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
private static $allowed_actions = [
|
2016-07-21 07:53:59 +02:00
|
|
|
'index',
|
|
|
|
'ping',
|
|
|
|
'Form',
|
|
|
|
'finished'
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
2016-07-21 07:53:59 +02:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
protected function init()
|
2016-07-21 07:53:59 +02:00
|
|
|
{
|
|
|
|
parent::init();
|
|
|
|
|
2017-04-01 12:02:18 +02:00
|
|
|
$page = $this->data();
|
|
|
|
|
2017-08-13 23:26:53 +02:00
|
|
|
$userforms = ModuleLoader::getModule('silverstripe/userforms');
|
|
|
|
$admin = ModuleLoader::getModule('silverstripe/admin');
|
2017-04-01 12:02:18 +02:00
|
|
|
// load the css
|
2017-08-11 01:33:06 +02:00
|
|
|
if (!$page->config()->get('block_default_userforms_css')) {
|
2017-08-13 23:26:53 +02:00
|
|
|
Requirements::css($userforms->getRelativeResourcePath('css/UserForm.css'));
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
2017-04-01 12:02:18 +02:00
|
|
|
// load the jquery
|
2017-08-11 01:33:06 +02:00
|
|
|
if (!$page->config()->get('block_default_userforms_js')) {
|
2017-08-13 23:26:53 +02:00
|
|
|
$lang = i18n::getData()->languageName(i18n::get_locale());
|
2017-08-11 01:33:06 +02:00
|
|
|
|
2017-08-13 23:26:53 +02:00
|
|
|
Requirements::javascript($admin->getRelativeResourcePath('thirdparty/jquery/jquery.js'));
|
2017-08-11 01:33:06 +02:00
|
|
|
Requirements::javascript(
|
2017-08-13 23:26:53 +02:00
|
|
|
$userforms->getRelativeResourcePath('thirdparty/jquery-validate/jquery.validate.min.js')
|
2017-08-11 01:33:06 +02:00
|
|
|
);
|
2017-08-13 23:26:53 +02:00
|
|
|
Requirements::add_i18n_javascript($userforms->getRelativeResourcePath('javascript/lang'));
|
|
|
|
Requirements::javascript($userforms->getRelativeResourcePath('javascript/UserForm.js'));
|
|
|
|
|
|
|
|
// @todo implement the $lang correctly
|
|
|
|
// Requirements::javascript(
|
|
|
|
// $userforms->getRelativeResourcePath("thirdparty/jquery-validate/localization/messages_{$lang}.min.js")
|
|
|
|
// );
|
|
|
|
// Requirements::javascript(
|
|
|
|
// $userforms->getRelativeResourcePath("thirdparty/jquery-validate/localization/methods_{$lang}.min.js")
|
|
|
|
// );
|
2017-08-11 01:33:06 +02:00
|
|
|
|
|
|
|
// Bind a confirmation message when navigating away from a partially completed form.
|
|
|
|
if ($page::config()->get('enable_are_you_sure')) {
|
2017-08-13 23:26:53 +02:00
|
|
|
Requirements::javascript(
|
|
|
|
$userforms->getRelativeResourcePath('thirdparty/jquery.are-you-sure/jquery.are-you-sure.js')
|
|
|
|
);
|
2017-08-11 01:33:06 +02:00
|
|
|
}
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Using $UserDefinedForm in the Content area of the page shows
|
|
|
|
* where the form should be rendered into. If it does not exist
|
|
|
|
* then default back to $Form.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
if ($this->Content && $form = $this->Form()) {
|
|
|
|
$hasLocation = stristr($this->Content, '$UserDefinedForm');
|
|
|
|
if ($hasLocation) {
|
2017-08-13 23:26:53 +02:00
|
|
|
$content = preg_replace(
|
|
|
|
'/(<p[^>]*>)?\\$UserDefinedForm(<\\/p>)?/i',
|
|
|
|
$form->forTemplate(),
|
|
|
|
$this->Content
|
|
|
|
);
|
2017-08-11 01:33:06 +02:00
|
|
|
return [
|
2016-07-21 07:53:59 +02:00
|
|
|
'Content' => DBField::create_field('HTMLText', $content),
|
2017-08-11 01:33:06 +02:00
|
|
|
'Form' => ''
|
|
|
|
];
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
return [
|
2016-07-21 07:53:59 +02:00
|
|
|
'Content' => DBField::create_field('HTMLText', $this->Content),
|
|
|
|
'Form' => $this->Form()
|
2017-08-11 01:33:06 +02:00
|
|
|
];
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Keep the session alive for the user.
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function ping()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the form for the page. Form can be modified by calling {@link updateForm()}
|
|
|
|
* on a UserDefinedForm extension.
|
|
|
|
*
|
|
|
|
* @return Forms
|
|
|
|
*/
|
|
|
|
public function Form()
|
|
|
|
{
|
2017-04-18 03:11:32 +02:00
|
|
|
$form = UserForm::create($this, 'Form_' . $this->ID);
|
2017-08-14 00:08:22 +02:00
|
|
|
/** @skipUpgrade */
|
|
|
|
$form->setFormAction(Controller::join_links($this->Link(), 'Form'));
|
2016-07-21 07:53:59 +02:00
|
|
|
$this->generateConditionalJavascript();
|
|
|
|
return $form;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate the javascript for the conditional field show / hiding logic.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function generateConditionalJavascript()
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
$default = '';
|
|
|
|
$rules = '';
|
2016-07-21 07:53:59 +02:00
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$watch = [];
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
if ($this->Fields()) {
|
2017-04-28 00:22:15 +02:00
|
|
|
/** @var EditableFormField $field */
|
2016-07-21 07:53:59 +02:00
|
|
|
foreach ($this->Fields() as $field) {
|
2017-04-28 00:22:15 +02:00
|
|
|
if ($result = $field->formatDisplayRules()) {
|
|
|
|
$watch[] = $result;
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($watch) {
|
2017-04-28 00:22:15 +02:00
|
|
|
$rules .= $this->buildWatchJS($watch);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2013-02-27 04:05:30 +01:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
// Only add customScript if $default or $rules is defined
|
2017-04-28 00:22:15 +02:00
|
|
|
if ($rules) {
|
2016-07-21 07:53:59 +02:00
|
|
|
Requirements::customScript(<<<JS
|
2017-04-28 00:22:15 +02:00
|
|
|
(function($) {
|
|
|
|
$(document).ready(function() {
|
|
|
|
{$rules}
|
|
|
|
});
|
|
|
|
})(jQuery);
|
2009-04-21 05:44:13 +02:00
|
|
|
JS
|
2017-08-11 02:37:03 +02:00
|
|
|
, 'UserFormsConditional');
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the form that is submitted through the site
|
|
|
|
*
|
|
|
|
* {@see UserForm::validate()} for validation step prior to processing
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @param Form $form
|
|
|
|
*
|
|
|
|
* @return Redirection
|
|
|
|
*/
|
|
|
|
public function process($data, $form)
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
$submittedForm = SubmittedForm::create();
|
2017-08-15 00:49:13 +02:00
|
|
|
$submittedForm->SubmittedByID = Security::getCurrentUser() ? Security::getCurrentUser()->ID : 0;
|
2016-07-21 07:53:59 +02:00
|
|
|
$submittedForm->ParentID = $this->ID;
|
|
|
|
|
|
|
|
// if saving is not disabled save now to generate the ID
|
|
|
|
if (!$this->DisableSaveSubmissions) {
|
|
|
|
$submittedForm->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
$attachments = array();
|
2017-08-11 01:33:06 +02:00
|
|
|
$submittedFields = ArrayList::create();
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
foreach ($this->Fields() as $field) {
|
|
|
|
if (!$field->showInReports()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$submittedField = $field->getSubmittedFormField();
|
|
|
|
$submittedField->ParentID = $submittedForm->ID;
|
|
|
|
$submittedField->Name = $field->Name;
|
|
|
|
$submittedField->Title = $field->getField('Title');
|
|
|
|
|
|
|
|
// save the value from the data
|
|
|
|
if ($field->hasMethod('getValueFromData')) {
|
|
|
|
$submittedField->Value = $field->getValueFromData($data);
|
|
|
|
} else {
|
|
|
|
if (isset($data[$field->Name])) {
|
|
|
|
$submittedField->Value = $data[$field->Name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($data[$field->Name])) {
|
2017-08-09 01:55:09 +02:00
|
|
|
if (in_array(EditableFileField::class, $field->getClassAncestry())) {
|
2017-03-02 00:46:13 +01:00
|
|
|
if (!empty($_FILES[$field->Name]['name'])) {
|
2016-07-21 07:53:59 +02:00
|
|
|
$foldername = $field->getFormField()->getFolderName();
|
|
|
|
|
|
|
|
// create the file from post data
|
2017-08-11 01:33:06 +02:00
|
|
|
$upload = Upload::create();
|
|
|
|
$file = File::create();
|
2016-07-21 07:53:59 +02:00
|
|
|
$file->ShowInSearch = 0;
|
|
|
|
try {
|
|
|
|
$upload->loadIntoFile($_FILES[$field->Name], $file, $foldername);
|
|
|
|
} catch (ValidationException $e) {
|
|
|
|
$validationResult = $e->getResult();
|
|
|
|
$form->addErrorMessage($field->Name, $validationResult->message(), 'bad');
|
|
|
|
Controller::curr()->redirectBack();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write file to form field
|
|
|
|
$submittedField->UploadedFileID = $file->ID;
|
|
|
|
|
|
|
|
// attach a file only if lower than 1MB
|
2017-08-11 01:33:06 +02:00
|
|
|
if ($file->getAbsoluteSize() < 1024 * 1024 * 1) {
|
2016-07-21 07:53:59 +02:00
|
|
|
$attachments[] = $file;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$submittedField->extend('onPopulationFromField', $field);
|
|
|
|
|
|
|
|
if (!$this->DisableSaveSubmissions) {
|
|
|
|
$submittedField->write();
|
|
|
|
}
|
|
|
|
|
|
|
|
$submittedFields->push($submittedField);
|
|
|
|
}
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$emailData = [
|
2017-08-15 00:49:13 +02:00
|
|
|
'Sender' => Security::getCurrentUser(),
|
2017-08-11 01:33:06 +02:00
|
|
|
'Fields' => $submittedFields
|
|
|
|
];
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
$this->extend('updateEmailData', $emailData, $attachments);
|
|
|
|
|
|
|
|
// email users on submit.
|
|
|
|
if ($recipients = $this->FilteredEmailRecipients($data, $form)) {
|
|
|
|
foreach ($recipients as $recipient) {
|
2017-08-15 00:49:13 +02:00
|
|
|
$email = Email::create()
|
|
|
|
->setHTMLTemplate('email/SubmittedFormEmail.ss')
|
|
|
|
->setPlainTemplate('email/SubmittedFormEmail.ss');
|
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$mergeFields = $this->getMergeFieldsMap($emailData['Fields']);
|
2017-04-01 12:02:18 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
if ($attachments) {
|
|
|
|
foreach ($attachments as $file) {
|
2017-08-11 01:33:06 +02:00
|
|
|
if (!$file->ID != 0) {
|
|
|
|
continue;
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2017-08-11 01:33:06 +02:00
|
|
|
|
|
|
|
$email->attachFile(
|
|
|
|
$file->Filename,
|
|
|
|
$file->Filename,
|
|
|
|
HTTP::get_mime_type($file->Filename)
|
|
|
|
);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-01 12:02:18 +02:00
|
|
|
|
2016-07-21 07:53:59 +02:00
|
|
|
$parsedBody = SSViewer::execute_string($recipient->getEmailBodyContent(), $mergeFields);
|
|
|
|
|
|
|
|
if (!$recipient->SendPlain && $recipient->emailTemplateExists()) {
|
2017-08-15 00:49:13 +02:00
|
|
|
$email->setHTMLTemplate($recipient->EmailTemplate);
|
|
|
|
}
|
|
|
|
|
|
|
|
$email->setData($recipient);
|
|
|
|
foreach ($emailData as $key => $value) {
|
|
|
|
$email->addData($key, $value);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$email->setFrom($recipient->EmailFrom);
|
|
|
|
$email->setBody($parsedBody);
|
|
|
|
$email->setTo($recipient->EmailAddress);
|
|
|
|
$email->setSubject($recipient->EmailSubject);
|
|
|
|
|
|
|
|
if ($recipient->EmailReplyTo) {
|
|
|
|
$email->setReplyTo($recipient->EmailReplyTo);
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if they are a dynamic reply to. eg based on a email field a user selected
|
|
|
|
if ($recipient->SendEmailFromField()) {
|
|
|
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailFromField()->Name);
|
|
|
|
|
|
|
|
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
|
|
|
$email->setReplyTo($submittedFormField->Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check to see if they are a dynamic reciever eg based on a dropdown field a user selected
|
|
|
|
if ($recipient->SendEmailToField()) {
|
|
|
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailToField()->Name);
|
|
|
|
|
|
|
|
if ($submittedFormField && is_string($submittedFormField->Value)) {
|
|
|
|
$email->setTo($submittedFormField->Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to see if there is a dynamic subject
|
|
|
|
if ($recipient->SendEmailSubjectField()) {
|
|
|
|
$submittedFormField = $submittedFields->find('Name', $recipient->SendEmailSubjectField()->Name);
|
|
|
|
|
|
|
|
if ($submittedFormField && trim($submittedFormField->Value)) {
|
|
|
|
$email->setSubject($submittedFormField->Value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->extend('updateEmail', $email, $recipient, $emailData);
|
|
|
|
|
|
|
|
if ($recipient->SendPlain) {
|
|
|
|
$body = strip_tags($recipient->getEmailBodyContent()) . "\n";
|
|
|
|
if (isset($emailData['Fields']) && !$recipient->HideFormData) {
|
|
|
|
foreach ($emailData['Fields'] as $Field) {
|
2017-08-11 01:33:06 +02:00
|
|
|
$body .= $Field->Title . ': ' . $Field->Value . " \n";
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$email->setBody($body);
|
|
|
|
$email->sendPlain();
|
|
|
|
} else {
|
|
|
|
$email->send();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$submittedForm->extend('updateAfterProcess');
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$session = $this->getRequest()->getSession();
|
|
|
|
$session->clear("FormInfo.{$form->FormName()}.errors");
|
|
|
|
$session->clear("FormInfo.{$form->FormName()}.data");
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
$referrer = (isset($data['Referrer'])) ? '?referrer=' . urlencode($data['Referrer']) : "";
|
|
|
|
|
|
|
|
// set a session variable from the security ID to stop people accessing
|
|
|
|
// the finished method directly.
|
|
|
|
if (!$this->DisableAuthenicatedFinishAction) {
|
|
|
|
if (isset($data['SecurityID'])) {
|
2017-08-11 01:33:06 +02:00
|
|
|
$session->set('FormProcessed', $data['SecurityID']);
|
2016-07-21 07:53:59 +02:00
|
|
|
} else {
|
|
|
|
// if the form has had tokens disabled we still need to set FormProcessed
|
|
|
|
// to allow us to get through the finshed method
|
|
|
|
if (!$this->Form()->getSecurityToken()->isEnabled()) {
|
|
|
|
$randNum = rand(1, 1000);
|
|
|
|
$randHash = md5($randNum);
|
2017-08-11 01:33:06 +02:00
|
|
|
$session->set('FormProcessed', $randHash);
|
|
|
|
$session->set('FormProcessedNum', $randNum);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$this->DisableSaveSubmissions) {
|
2017-08-11 01:33:06 +02:00
|
|
|
$session->set('userformssubmission'. $this->ID, $submittedForm->ID);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
return $this->redirect($this->Link('finished') . $referrer . $this->config()->get('finished_anchor'));
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Allows the use of field values in email body.
|
|
|
|
*
|
|
|
|
* @param ArrayList fields
|
|
|
|
* @return ArrayData
|
|
|
|
*/
|
2017-08-15 00:49:13 +02:00
|
|
|
protected function getMergeFieldsMap($fields = [])
|
2016-07-21 07:53:59 +02:00
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
$data = ArrayData::create([]);
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
$data->setField($field->Name, DBField::create_field('Text', $field->Value));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This action handles rendering the "finished" message, which is
|
|
|
|
* customizable by editing the ReceivedFormSubmission template.
|
|
|
|
*
|
|
|
|
* @return ViewableData
|
|
|
|
*/
|
|
|
|
public function finished()
|
|
|
|
{
|
2017-08-11 01:33:06 +02:00
|
|
|
$submission = $this->getRequest()->getSession()->get('userformssubmission'. $this->ID);
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
if ($submission) {
|
|
|
|
$submission = SubmittedForm::get()->byId($submission);
|
|
|
|
}
|
|
|
|
|
|
|
|
$referrer = isset($_GET['referrer']) ? urldecode($_GET['referrer']) : null;
|
|
|
|
|
|
|
|
if (!$this->DisableAuthenicatedFinishAction) {
|
2017-08-11 01:33:06 +02:00
|
|
|
$formProcessed = $this->getRequest()->getSession()->get('FormProcessed');
|
2016-07-21 07:53:59 +02:00
|
|
|
|
|
|
|
if (!isset($formProcessed)) {
|
|
|
|
return $this->redirect($this->Link() . $referrer);
|
|
|
|
} else {
|
2017-08-11 01:33:06 +02:00
|
|
|
$securityID = $this->getRequest()->getSession()->get('SecurityID');
|
2016-07-21 07:53:59 +02:00
|
|
|
// make sure the session matches the SecurityID and is not left over from another form
|
|
|
|
if ($formProcessed != $securityID) {
|
|
|
|
// they may have disabled tokens on the form
|
2017-08-11 01:33:06 +02:00
|
|
|
$securityID = md5($this->getRequest()->getSession()->get('FormProcessedNum'));
|
2016-07-21 07:53:59 +02:00
|
|
|
if ($formProcessed != $securityID) {
|
|
|
|
return $this->redirect($this->Link() . $referrer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$this->getRequest()->getSession()->clear('FormProcessed');
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
$data = [
|
|
|
|
'Submission' => $submission,
|
|
|
|
'Link' => $referrer
|
|
|
|
];
|
2017-04-21 01:35:37 +02:00
|
|
|
|
|
|
|
$this->extend('updateReceivedFormSubmissionData', $data);
|
|
|
|
|
2017-08-11 01:33:06 +02:00
|
|
|
return $this->customise([
|
2017-08-14 02:29:57 +02:00
|
|
|
'Content' => $this->customise($data)->renderWith(__CLASS__ . '_ReceivedFormSubmission'),
|
2016-07-21 07:53:59 +02:00
|
|
|
'Form' => '',
|
2017-08-11 01:33:06 +02:00
|
|
|
]);
|
2016-07-21 07:53:59 +02:00
|
|
|
}
|
2017-04-28 00:22:15 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Outputs the required JS from the $watch input
|
|
|
|
*
|
|
|
|
* @param array $watch
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
protected function buildWatchJS($watch)
|
|
|
|
{
|
|
|
|
$result = '';
|
|
|
|
foreach ($watch as $key => $rule) {
|
|
|
|
$events = implode(' ', $rule['events']);
|
|
|
|
$selectors = implode(', ', $rule['selectors']);
|
|
|
|
$conjunction = $rule['conjunction'];
|
|
|
|
$operations = implode(" {$conjunction} ", $rule['operations']);
|
|
|
|
$target = $rule['targetFieldID'];
|
|
|
|
|
|
|
|
$result .= <<<EOS
|
|
|
|
\n
|
|
|
|
$('.userform').on('{$events}',
|
|
|
|
"{$selectors}",
|
|
|
|
function (){
|
2017-05-22 05:54:28 +02:00
|
|
|
if ({$operations}) {
|
|
|
|
$('{$target}').{$rule['view']};
|
2017-04-28 00:22:15 +02:00
|
|
|
} else {
|
2017-05-22 05:54:28 +02:00
|
|
|
$('{$target}').{$rule['opposite']};
|
2017-04-28 00:22:15 +02:00
|
|
|
}
|
2017-05-01 07:44:39 +02:00
|
|
|
});
|
2017-06-06 00:13:09 +02:00
|
|
|
$("{$target}").find('.hide').removeClass('hide');
|
2017-04-28 00:22:15 +02:00
|
|
|
EOS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
2008-09-29 05:18:23 +02:00
|
|
|
}
|