diff --git a/code/UserDefinedForm.php b/code/UserDefinedForm.php index 7557051..eeb3b9b 100755 --- a/code/UserDefinedForm.php +++ b/code/UserDefinedForm.php @@ -345,11 +345,10 @@ class UserDefinedForm_Controller extends Page_Controller { $submittedField->write(); $submittedFields->push($submittedField); - - if(!empty( $data[$field->Name])){ - switch($field->ClassName){ - + if(!empty($data[$field->Name])){ + + switch($field->ClassName){ case "EditableEmailField" : if($field->SendCopy){ $recipientAddresses[] = $data[$field->Name]; @@ -359,50 +358,52 @@ class UserDefinedForm_Controller extends Page_Controller { break; case "EditableFileField" : - - // Returns a file type which we attach to the email. - $submittedfile = $field->createSubmittedField($data[$field->Name], $submittedForm); - $file = $submittedfile->UploadedFile(); - - $filename = $file->getFilename(); - - // Attach the file if its less than 1MB, provide a link if its over. - if($file->getAbsoluteSize() < 1024*1024*1){ - $attachments[] = $file; - } - - // Always provide the link if present. - if($file->ID) { - $submittedField->Value = $values[$field->Title] = "Uploaded to: ". Director::absoluteBaseURL(). $filename . ""; - } else { - $submittedField->Value = $values[$field->Title] = ""; + if(isset($_FILES[$field->Name])) { + + // create the file from post data + $upload = new Upload(); + $file = new File(); + $upload->loadIntoFile($_FILES[$field->Name], $file); + + // write file to form field + $submittedField->UploadedFileID = $file->ID; + + // Attach the file if its less than 1MB, provide a link if its over. + if($file->getAbsoluteSize() < 1024*1024*1){ + $attachments[] = $file; + } + + // Always provide the link if present. + if($file->ID) { + $submittedField->Value = "getFilename() ."\" title=\"". $file->getFilename() . "\">". $file->Title . ""; + } else { + $submittedField->Value = ""; + } + $submittedField->write(); } break; } - - }elseif( $field->hasMethod( 'getValueFromData' ) ) { - $values[$field->Title] = Convert::linkIfMatch($field->getValueFromData( $data )); - - } else { - if(isset($data[$field->Name])) $values[$field->Title] = Convert::linkIfMatch($data[$field->Name]); } - } $emailData = array( "Sender" => Member::currentUser(), "Fields" => $submittedFields, ); - + // email users on submit. All have their own custom options. if($this->EmailRecipients()) { $email = new UserDefinedForm_SubmittedFormEmail($submittedFields); $email->populateTemplate($emailData); if($attachments){ foreach($attachments as $file){ - $email->attachFile($filename,$filename); + // bug with double decorated fields, valid ones should have an ID. + if($file->ID != 0) { + $email->attachFile($file->Filename,$file->Filename, $file->getFileType()); + } } } + foreach($this->EmailRecipients() as $recipient) { $email->populateTemplate($emailData); $email->setFrom($recipient->EmailFrom); @@ -458,12 +459,6 @@ class UserDefinedForm_Controller extends Page_Controller { return $templateData; } - - function deletesubmissions() { - // delete all the submissions - - return true; - } } /** diff --git a/code/editor/EditableFileField.php b/code/editor/EditableFileField.php index 53117c7..b16290d 100755 --- a/code/editor/EditableFileField.php +++ b/code/editor/EditableFileField.php @@ -24,6 +24,7 @@ class EditableFileField extends EditableFormField { public static $allowed_extensions = array(); static $singular_name = 'File field'; + static $plural_names = 'File fields'; function getFormField() { @@ -36,29 +37,5 @@ class EditableFileField extends EditableFormField { function getSimpleFormField(){ return new FileField($this->Name, $this->Title, $this->getField('Default')); } - - function createSubmittedField($data, $submittedForm, $fieldClass = "SubmittedFileField") { - if(!$_FILES[$this->Name]) - return null; - - $submittedField = new $fieldClass(); - $submittedField->Title = $this->Title; - $submittedField->Name = $this->Name; - $submittedField->ParentID = $submittedForm->ID; - - // create the file from post data - $upload = new Upload(); - $upload->setAllowedExtensions(self::$allowed_extensions); - $upload->setAllowedMaxFileSize(self::$allowed_max_file_size); - - // upload file - $upload->load($_FILES[$this->Name]); - - $uploadedFile = $upload->getFile(); - $submittedField->UploadedFileID = $uploadedFile->ID; - $submittedField->write(); - - return $submittedField; - } } ?> \ No newline at end of file diff --git a/code/editor/FieldEditor.php b/code/editor/FieldEditor.php index 3f1bf79..a7ea019 100755 --- a/code/editor/FieldEditor.php +++ b/code/editor/FieldEditor.php @@ -37,7 +37,7 @@ class FieldEditor extends FormField { $relationName = $this->name; $fields = $this->form->getRecord()->$relationName(); - + if($this->readonly) { $readonlyFields = new DataObjectSet(); diff --git a/code/editor/SubmittedFormReportField.php b/code/editor/SubmittedFormReportField.php index eb01619..c6cb049 100755 --- a/code/editor/SubmittedFormReportField.php +++ b/code/editor/SubmittedFormReportField.php @@ -40,7 +40,7 @@ class SubmittedFormReportField extends FormField { * @return HTTPResponse / bool */ public function export() { - $now = Date("Y-m-d_h.i.s"); + $now = Date("Y-m-d_h.i.s"); $fileName = "export-$now.csv"; $separator = ","; diff --git a/javascript/UserForm.js b/javascript/UserForm.js index 17dd3e2..2015908 100644 --- a/javascript/UserForm.js +++ b/javascript/UserForm.js @@ -89,6 +89,7 @@ */ $(".EditableFormField .delete").livequery('click', function() { $(this).parents(".EditableFormField").remove(); + return false; }); /** diff --git a/templates/SubmittedFormReportField.ss b/templates/SubmittedFormReportField.ss index dc8a196..ea0005f 100644 --- a/templates/SubmittedFormReportField.ss +++ b/templates/SubmittedFormReportField.ss @@ -18,7 +18,7 @@ <% control FieldValues %> $Title - <% if Link %><% end_if %>$Value<% if Link %><% end_if %> + $Value.RAW <% end_control %> diff --git a/templates/email/SubmittedFormEmail.ss b/templates/email/SubmittedFormEmail.ss index 6b950ff..ad0ed57 100755 --- a/templates/email/SubmittedFormEmail.ss +++ b/templates/email/SubmittedFormEmail.ss @@ -1,17 +1,11 @@ - - - - -

$Subject

- $Body +

$Subject

+$Body - - <% control Fields %> - - - - - <% end_control %> -
$Title$Value
- - + + <% control Fields %> + + + + + <% end_control %> +
$Title$Value.RAW
diff --git a/templates/email/SubmittedFormEmailToSubmitter.ss b/templates/email/SubmittedFormEmailToSubmitter.ss index fe4d1ae..5bf0acd 100644 --- a/templates/email/SubmittedFormEmailToSubmitter.ss +++ b/templates/email/SubmittedFormEmailToSubmitter.ss @@ -1,21 +1,12 @@ - - - - +$Body - $Body - -

- <% _t('SUBMITTED',"You have submitted the following information:") %> -

+

<% _t('SUBMITTED',"You have submitted the following information:") %>

- - <% control Fields %> - - - - - <% end_control %> -
$Title$Value
- - + + <% control Fields %> + + + + + <% end_control %> +
$Title$Value.RAW
\ No newline at end of file