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.
<?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(); ?>
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?