public function definition_after_data() {
        $mform = $this->_form;
        $cohortfile = $mform->getElementValue('cohortfile');
        $allowsubmitform = false;
        if ($cohortfile && ($file = $this->get_cohort_file($cohortfile))) {
            // File was uploaded. Parse it.
            $encoding = $mform->getElementValue('encoding')[0];
            $delimiter = $mform->getElementValue('delimiter')[0];
            $contextid = $mform->getElementValue('contextid')[0];
            if (!empty($contextid) && ($context = context::instance_by_id($contextid, IGNORE_MISSING))) {
                $this->processeddata = $this->process_upload_file($file, $encoding, $delimiter, $context);
                if ($this->processeddata && count($this->processeddata) > 1 && !$this->processeddata[0]['errors']) {
                    $allowsubmitform = true;
                }
            }
        }
        if (!$allowsubmitform) {
            // Hide submit button.
            $el = $mform->getElement('buttonar')->getElements()[0];
            $el->setValue('');
            $el->freeze();
        } else {
            $mform->setExpanded('cohortfileuploadform', false);
        }

    }
public function definition_after_data() {
        $mform = $this->_form;
        $cohortfile = $mform->getElementValue('cohortfile');
        $allowsubmitform = false;
        if ($cohortfile && ($file = $this->get_cohort_file($cohortfile))) {
            // File was uploaded. Parse it.
            $encoding = $mform->getElementValue('encoding')[0];
            $delimiter = $mform->getElementValue('delimiter')[0];
            $contextid = $mform->getElementValue('contextid')[0];
            if (!empty($contextid) && ($context = context::instance_by_id($contextid, IGNORE_MISSING))) {
                $this->processeddata = $this->process_upload_file($file, $encoding, $delimiter, $context);
                if ($this->processeddata && count($this->processeddata) > 1 && !$this->processeddata[0]['errors']) {
                    $allowsubmitform = true;
                }
            }
        }
        if (!$allowsubmitform) {
            // Hide submit button.
            $el = $mform->getElement('buttonar')->getElements()[0];
            $el->setValue('');
            $el->freeze();
        } else {
            $mform->setExpanded('cohortfileuploadform', false);
        }

    }
public function definition_after_data ( ) { $ mform = $ this -> _form ; $ cohortfile = $ mform -> getElementValue ( 'cohortfile' ) ; $ allowsubmitform = false ; if ( $ cohortfile && ( $ file = $ this -> get_cohort_file ( $ cohortfile ) ) ) { // File was uploaded. Parse it. $ encoding = $ mform -> getElementValue ( 'encoding' ) [ 0 ] ; $ delimiter = $ mform -> getElementValue ( 'delimiter' ) [ 0 ] ; $ contextid = $ mform -> getElementValue ( 'contextid' ) [ 0 ] ; if ( ! empty ( $ contextid ) && ( $ context = context :: instance_by_id ( $ contextid , IGNORE_MISSING ) ) ) { $ this -> processeddata = $ this -> process_upload_file ( $ file , $ encoding , $ delimiter , $ context ) ; if ( $ this -> processeddata && count ( $ this -> processeddata ) > 1 && ! $ this -> processeddata [ 0 ] [ 'errors' ] ) { $ allowsubmitform = true ; } } } if ( ! $ allowsubmitform ) { // Hide submit button. $ el = $ mform -> getElement ( 'buttonar' ) -> getElements ( ) [ 0 ] ; $ el -> setValue ( '' ) ; $ el -> freeze ( ) ; } else { $ mform -> setExpanded ( 'cohortfileuploadform' , false ) ; } }
Process the uploaded file and allow the submit button only if it doest not have errors.
Process the uploaded file and allow the submit button only if it doest not have errors .