mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
BUGFIX: tidied up file attachment. should no longer attach blank file objects
This commit is contained in:
parent
c6768d8412
commit
703a62cd7f
@ -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] = "<a href=\"". $filename ."\" title=\"". Director::absoluteBaseURL(). $filename. "\">Uploaded to: ". Director::absoluteBaseURL(). $filename . "</a>";
|
||||
} 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 = "<a href=\"". $file->getFilename() ."\" title=\"". $file->getFilename() . "\">". $file->Title . "</a>";
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
?>
|
@ -37,7 +37,7 @@ class FieldEditor extends FormField {
|
||||
$relationName = $this->name;
|
||||
|
||||
$fields = $this->form->getRecord()->$relationName();
|
||||
|
||||
|
||||
if($this->readonly) {
|
||||
$readonlyFields = new DataObjectSet();
|
||||
|
||||
|
@ -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 = ",";
|
||||
|
||||
|
@ -89,6 +89,7 @@
|
||||
*/
|
||||
$(".EditableFormField .delete").livequery('click', function() {
|
||||
$(this).parents(".EditableFormField").remove();
|
||||
return false;
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@
|
||||
<% control FieldValues %>
|
||||
<tr>
|
||||
<td class="field">$Title</td>
|
||||
<td class="value"><% if Link %><a href="$Link"><% end_if %>$Value<% if Link %></a><% end_if %></td>
|
||||
<td class="value">$Value.RAW</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</table>
|
||||
|
@ -1,17 +1,11 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<h1>$Subject</h1>
|
||||
$Body
|
||||
<h1>$Subject</h1>
|
||||
$Body
|
||||
|
||||
<table>
|
||||
<% control Fields %>
|
||||
<tr>
|
||||
<td style="padding: 5px"><b>$Title</b></td>
|
||||
<td style="padding: 5px">$Value</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
<table>
|
||||
<% control Fields %>
|
||||
<tr>
|
||||
<td style="padding: 5px"><b>$Title</b></td>
|
||||
<td style="padding: 5px">$Value.RAW</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</table>
|
||||
|
@ -1,21 +1,12 @@
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
$Body
|
||||
|
||||
$Body
|
||||
|
||||
<p>
|
||||
<% _t('SUBMITTED',"You have submitted the following information:") %>
|
||||
</p>
|
||||
<p><% _t('SUBMITTED',"You have submitted the following information:") %></p>
|
||||
|
||||
<table>
|
||||
<% control Fields %>
|
||||
<tr>
|
||||
<td style="padding: 5px"><b>$Title</b></td>
|
||||
<td style="padding: 5px">$Value</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
<table>
|
||||
<% control Fields %>
|
||||
<tr>
|
||||
<td style="padding: 5px"><b>$Title</b></td>
|
||||
<td style="padding: 5px">$Value.RAW</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</table>
|
Loading…
Reference in New Issue
Block a user