Wednesday, November 14, 2012

FileUpload from Nick Baker, file required or data not saved

My CakePHP 1.3 app uses FileUPload from Nick Baker, and it all works well,
except that when I try and add a new study or edit one, if I don't choose a
file, the data is lost and changes not saved. This is very frustrating,
especially if I just want to change the inclusion or exclusion criteria or
even the name of the study.

I tried the patch given here: sdoney patch
<https://github.com/sdoney/CakePHP-FileUpload-Plugin/commit/693a9b7d20f0ce4fac921ee3939e547cdf18baa9>

However that didn't change anything(Unless there's a certain way I have to
apply the changes?) Or could it be that I didn't use the defaults for the
name field? Any help is appreciated.

Model:
<?php
class Study extends AppModel {
var $name = 'Study';
var $displayField = 'studyname';
var $actsAs = array('ExtendAssociations','FileUpload.FileUpload' => array(
'uploadDir' => 'pdfs',
'forceWebroot' => true, //if false, uploads will be saved to the
uploadDir as a direct path.
//default: true
'fields' => array(
'name' => 'consent_form',
'type' => 'type',
'size' => 'size'
),
'allowedTypes' => array(
'pdf' => array('application/pdf')
),
'required' => false,
'allowEmpty' => true,
'maxFileSize' => '10485760', //in bytes
'unique' => false, //uploaded files will overwrite existing files
//'fileNameFunction' => false, //execute sha1 on fileName
)
);

View to add new study

<?php
$javascript->link('study_links', false);
?>
<div class="studies form">
<?php echo $this->Form->create('Study', array('type' => 'file'));?>
<fieldset>
<legend><?php __('Add Study'); ?></legend>
<?php
echo $this->Form->input('studyname', array('label'=>'Study
Name','required' => true));
echo $this->Form->input('studynumber', array('label'=>'Study
Number','required' => true));
echo $this->Form->input('file', array('label'=>'Select Electronic
Consent','type' => 'file'));
echo $this->Form->input('consent_form_date');
?>
<fieldset class="inclusion">
<legend><?php __('Inclusions'); ?></legend>
<div class="IncExc">
<?php
echo $this->Form->input('Inclusion',array(
'label' => false,
'type' => 'select',
'multiple' => 'checkbox',
'options' => $inclusions,
'selected' => $html->value('Inclusion.Inclusion'),
));
?>
</fieldset>
<?php echo $this->Form->end(__('Submit', true));?>
</div>
<div class="actions">

<?php __('Actions'); ?>

<ul>
<li><?php echo $this->Html->link(__('List Studies', true),
array('action' => 'index'));?></li>
</ul>
</div>






--
View this message in context: http://cakephp.1045679.n5.nabble.com/FileUpload-from-Nick-Baker-file-required-or-data-not-saved-tp5712273.html
Sent from the CakePHP mailing list archive at Nabble.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.

No comments: