Asking for file name

master
Nathan Adams 2016-10-01 22:10:30 -05:00
parent 39245dc42c
commit e398a3bbd6
3 changed files with 31 additions and 2 deletions

View File

@ -53,6 +53,15 @@ class IDF_Form_Upload extends Pluf_Form
'size' => 67,
),
));
$this->fields['ext_file_name'] = new Pluf_Form_Field_Varchar(
array('required' => false,
'label' => __('External File Name'),
'initial' => '',
'widget_attrs' => array(
'maxlength' => 200,
'size' => 67,
),
));
$this->fields['changelog'] = new Pluf_Form_Field_Varchar(
array('required' => false,
'label' => __('Description'),
@ -133,9 +142,15 @@ class IDF_Form_Upload extends Pluf_Form
throw new Pluf_Form_Invalid(__('You provided an invalid label.'));
}
}
if (empty($this->cleaned_data["file"]) && empty($this->cleaned_data["ext_file"])) {
if (empty($this->cleaned_data["file"]) && empty($this->cleaned_data["ext_file"]) && empty($this->cleaned_data["ext_file_name"])) {
throw new Pluf_Form_Invalid(__("Must upload a file or specify an external file"));
}
foreach(explode(".", $this->cleaned_data["ext_file_name"]) as $section) {
if (!ctype_alpha($section)) {
throw new Pluf_Form_Invalid(__("External file name must not contain characters other than a-zA-Z and ."));
}
}
return $this->cleaned_data;
}
@ -188,7 +203,7 @@ class IDF_Form_Upload extends Pluf_Form
$upload->file = $this->cleaned_data['file'];
$upload->filesize = filesize(Pluf::f('upload_path').'/'.$this->project->shortname.'/files/'.$this->cleaned_data['file']);
} else {
$upload->file = end(explode("/", $this->cleaned_data["ext_file"]));
$upload->file = $this->cleaned_data["ext_file_name"];
$upload->ext_file = $this->cleaned_data['ext_file'];
}

View File

@ -63,6 +63,13 @@ class IDF_Upload extends Pluf_Model
'size' => 250,
'verbose' => __('External File URL'),
),
'ext_file_name' =>
array(
'type' => 'Pluf_DB_Field_Varchar',
'blank' => false,
'size' => 250,
'verbose' => __('External File Name'),
),
'changelog' =>
array(
'type' => 'Pluf_DB_Field_Text',

View File

@ -24,6 +24,13 @@
{$form.f.ext_file|unsafe}
</td>
</tr>
<tr>
<th><strong>{$form.f.ext_file_name.labelTag}:</strong></th>
<td>{if $form.f.ext_file_name.errors}{$form.f.ext_file_name.fieldErrors}{/if}
{$form.f.ext_file_name|unsafe}
</td>
</tr>
<tr>
<th>{$form.f.changelog.labelTag}:</th>
<td>{if $form.f.changelog.errors}{$form.f.changelog.fieldErrors}{/if}