Sending data to a Form - Moodle 3.9+

Sending data to a Form - Moodle 3.9+

by Dave Emsley -
Number of replies: 2

Hi all,

I have form (mypage.php)   to which I'm sending some data using:

require_once($CFG->dirroot.'/user/profile/lib.php'); 
$pur = profile_user_record($USER->id);
$toform = array('firstname'=>$USER->firstname,'lastname'=>$USER->lastname, 'email'=>$USER->email , 'businessunit'=>$pur->businessunit);
$request_course->set_data($toform);    

The resulting form is correctly displayed.

However I want then to find all users in the same "Business Unit" and thought that within mypage_form.php I could use $toform['businessunit'] but this appears not to be the case as $toform doesn't exist.

I'm clearly missing something that should be obvious but not to me.

Any advice greatly appreciated.

Many Thanks

Dave


Average of ratings: -
In reply to Dave Emsley

Re: Sending data to a Form - Moodle 3.9+

by coactum Entwickler -
Picture of Plugin developers

Hi Dave,

with the "->set_data($toform)" you only set the default values of the form fields.

If you want to pass parameters to a form and use them on mypage_form.php you have to pass them to the form class first:

$mform_mypage = new mypage_form( $action, array('email'=>$email, 'username'=>$username ) );

Then you can use them in the form definition as $this->_customdata['email'].

For detailed desription see here.

Hope this can help you.



Average of ratings: Useful (1)