cmc-sales/php/app/views/attachments/add.ctp

43 lines
1.1 KiB
PHP

<div class="attachments form">
<?php echo $form->create('Attachment', array('type'=>'file', 'url' => array('controller' => 'attachments', 'action' => 'add')));?>
<fieldset>
<legend><?php __('Add Attachment');?></legend>
<?php
echo $form->input('principle_id');
echo $form->input('name');
echo $form->file('file');
echo $form->input('description');
// archived not needed for new uploads
?>
</fieldset>
<?php echo $form->end('Submit');?>
</div>
<script>
// Redirect back to attachments index on successful upload
$(document).ready(function() {
$('#AttachmentAddForm').submit(function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
var formData = new FormData(this);
$.ajax({
url: '/go/attachments/upload',
type: 'POST',
data: formData,
processData: false,
contentType: false,
success: function(response) {
alert('Attachment uploaded successfully');
window.location.href = '/attachments';
},
error: function(xhr) {
alert('Upload failed: ' + (xhr.responseText || 'Unknown error'));
}
});
return false;
});
});
</script>