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
@ -346,10 +346,9 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
$submittedField->write();
|
||||
$submittedFields->push($submittedField);
|
||||
|
||||
if(!empty( $data[$field->Name])){
|
||||
if(!empty($data[$field->Name])){
|
||||
|
||||
switch($field->ClassName){
|
||||
|
||||
case "EditableEmailField" :
|
||||
if($field->SendCopy){
|
||||
$recipientAddresses[] = $data[$field->Name];
|
||||
@ -359,12 +358,15 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
break;
|
||||
|
||||
case "EditableFileField" :
|
||||
if(isset($_FILES[$field->Name])) {
|
||||
|
||||
// Returns a file type which we attach to the email.
|
||||
$submittedfile = $field->createSubmittedField($data[$field->Name], $submittedForm);
|
||||
$file = $submittedfile->UploadedFile();
|
||||
// create the file from post data
|
||||
$upload = new Upload();
|
||||
$file = new File();
|
||||
$upload->loadIntoFile($_FILES[$field->Name], $file);
|
||||
|
||||
$filename = $file->getFilename();
|
||||
// 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){
|
||||
@ -373,21 +375,16 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
|
||||
// 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>";
|
||||
$submittedField->Value = "<a href=\"". $file->getFilename() ."\" title=\"". $file->getFilename() . "\">". $file->Title . "</a>";
|
||||
} else {
|
||||
$submittedField->Value = $values[$field->Title] = "";
|
||||
$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(),
|
||||
@ -400,9 +397,13 @@ class UserDefinedForm_Controller extends Page_Controller {
|
||||
$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;
|
||||
}
|
||||
}
|
||||
?>
|
@ -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>
|
||||
<table>
|
||||
<% control Fields %>
|
||||
<tr>
|
||||
<td style="padding: 5px"><b>$Title</b></td>
|
||||
<td style="padding: 5px">$Value</td>
|
||||
<td style="padding: 5px">$Value.RAW</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</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>
|
||||
<table>
|
||||
<% control Fields %>
|
||||
<tr>
|
||||
<td style="padding: 5px"><b>$Title</b></td>
|
||||
<td style="padding: 5px">$Value</td>
|
||||
<td style="padding: 5px">$Value.RAW</td>
|
||||
</tr>
|
||||
<% end_control %>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</table>
|
Loading…
Reference in New Issue
Block a user