Form document not posting as it should

Form document not posting as it should

by John Anton Thelander -
Number of replies: 1

Hello coders!

I hope your coding goes well. I have a problem with posting a Moodle form. I have tried for some time to get it to work and the "Cancel" button works just fine but the $mform->get_data() with the blue button "Save changes" doesn't seem to work at all though it seems that I'm doing it by the guide. It's a local plugin with the folder name "datfc" and it's being run on Moodle 2.8.5 on a XAMPP 1.8.2 server which contains Apache 2.4.4, MySQL 5.5.32, PHP 5.4.25 among other programs. The variable $courseid is declared earlier in the "index.php".

index.php
...
$usertimezone=$USER->timezone;
$customdata=array('courseid'=>$courseid,'usertimezone'=>$usertimezone);
$mform=new datfc_form(null,$customdata);
//Form processing and displaying is done here
    if ($mform->is_cancelled()){
        echo 'Cancel works!';
    }
    else if ($formdata=$mform->get_data()){
        echo 'The function $mform->get_data() works.';
    }
    
    //Print the header.
    echo $OUTPUT->header();
    echo $OUTPUT->heading('Course Dates Table Overview');
    
    local_datfc_display_course_start_date($courseid,$usertimezone);
    local_datfc_display_assignment_dates($courseid,$usertimezone);
    local_datfc_display_quiz_dates($courseid,$usertimezone);
    //displays the form
    $mform->display();
    //Print the footer.
    echo $OUTPUT->footer();
...
end of index.php
datfc_form.php
...
$mform=$this->_form;
        
        //Remove before sending in.
        $mform->disable_form_change_checker();
        
        $customdataarray=$this->_customdata;
        $courseid=$customdataarray['courseid'];
        
        $mform->addElement('header','toolselectheader',get_string('toolselectheader','local_datfc'));
        
        $tooloptions=array('1'=>'Course Date Rollover','2'=>'Course Date Table Adjustment');
        $mform->addElement('select','toolselect',get_string('toolselect','local_datfc'),$tooloptions);
        $mform->addHelpButton('toolselect','toolselect','local_datfc');
        
        $mform->addElement('header', 'rolloverheader', get_string('daterollovertextwithvariableheader', 'local_datfc'));
        
        $sqlcoursestartdate=$DB->get_fieldset_select('course','startdate','id=?',array($courseid));
        
        $defaulttimezone=date_default_timezone_get();
        date_default_timezone_set('Europe/London');
        
        $coursestartdate=date("Y-m-d",$sqlcoursestartdate[0]);
        
        date_default_timezone_set($defaulttimezone);    
        
        $startdatewithvariable=get_string('daterollovertextwithvariableshort','local_datfc',$coursestartdate);
        
        $allowedtimespan=array('startyear'=>2015,'stopyear'=>2030,'timezone'=>99,'optional'=>false);
        
        $mform->addElement('date_selector','rolloverdate',$startdatewithvariable,$allowedtimespan);
        $mform->addHelpButton('rolloverdate','daterollovertextwithoutvariableshort','local_datfc');
        
        $mform->addElement('hidden','courseid',$courseid);
        $mform->setType('courseid',PARAM_INT);
        
        $this->add_action_buttons();
...
end of datfc_form.php


I also have another question, should the form instantiation be made only with an equal sign or with an ampersand sign and an equal sign?

$mform=$this->_form;
or
$mform&=$this->_form;

Thank you very much in advance.

Best wishes,
John Anton Thelander

Average of ratings: -
In reply to John Anton Thelander

Svar: Form document not posting as it should

by John Anton Thelander -

Hi again!

It seems to work through another way, might post it here later. So no need to help me with my earlier post.

best wishes, thank you and God bless you
J. Anton Thelander