I am fairly new at Yii and PHP in general. I followed this tutorial http://www.yiiframework.com/wiki/2/ and am successfully able to upload and process a file.
Currently my form has only an activeFileField and a submitButton. User clicks the ‘choose file’ link, selects a file and clicks OK, and then the file name appears next to the choose file button, as it should. They then click the submit button, the form is submitted, and all’s well.
I would like to get rid of the submitButton and have the form submit automatically after the user has chosen a file. I can’t figure out how to do this.
Current view:
<?php echo CHtml::form($this->createUrl('project/readXML'), 'post', array('enctype' => 'multipart/form-data')); ?>
<?php echo CHtml::activeFileField($new, 'xmlFile'); ?>
<?php echo CHtml::submitButton();?>
<?php echo CHtml::endForm(); ?>
I was imagining there might be some event for the activeFileField I could attach some javascript to but it doesn’t look like there is any support for this.
What’s the best way to accomplish this? I don’t particularly need activeRecord behavior here – just need to load the file, read it, and perform some actions – then it gets discarded. Maybe I should just do it using regular form inputs? If so does anyone have an example of this?