Process moodleform in Block

Process moodleform in Block

by Brian Merritt -
Number of replies: 2
Picture of Particularly helpful Moodlers

I have set up a block with a form to input additional user profile field information (to save the user having to go to edit my profile, then scroll all the way down, and then find the additional fields.

    $mform_myblock = new myblockblock_form(null,array($formdefaults));
    $this->content->text .= $mform_myblock->render() ; // generate the form
    return $this->content ;;

The form displays OK (with a bit of CSS to make it fit into the block), but how do I now process the form output? I have returned the content via return->$this, so having output the form that function is finished

Average of ratings: -
In reply to Brian Merritt

Re: Process moodleform in Block

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

You need to process the form, by calling $mform_myblock->get_data(), before outputting it.

ie the steps are:

  1. Create the form instance
  2. Check to see if the form has been submitted, and if so, process the data 
  3. If the form has not been submitted, output it instead