+44 (0)2 0718 39207
info@enovationsolutions.co.uk
  • Client Support
  • FR
  • IE
EnovationEnovationEnovationEnovation
+44 (0)2 0718 39207
  • WHAT WE DO
    • OUR SERVICES
      • Consultancy
      • Content Creation
      • Build & Design
      • Training
      • Hosting
      • Support & Maintenance
    • OUR SOLUTIONS
      • Moodle
      • The LMS Totara Learn
      • Totara Social
      • Aura Talent
      • Mahara
  • WHO WE ARE
    • About Enovation
    • Careers
  • CASE STUDIES
    • Smyths Toys
    • Tata Chemicals Europe
    • Courts Service of Ireland
    • OpenJaw
    • New College Lanarkshire
  • OUR PARTNERS
    • IntelliBoard
    • BigBlueButton
  • INSIGHTS
  • CONTACT US

How to modify Moodle form elements before displaying the form

    Home Blog How to modify Moodle form elements before displaying the form

    How to modify Moodle form elements before displaying the form

    Greg Adamowicz | Blog, News | 3 June, 2014

    Forms in Moodle are both easy and hard to deal with. Easy, when you stick to standard form elements, without any solution specific modifications or design changes. And hard, when you have to break with standards or do some specific things with data.

    We’re going to look into how to modify form elements before form is rendered on clients browser. Specifically, when you need to check or uncheck an element under some condition that not necessary is handled by Moodle code.

    Moodle is giving you a definition_after_data method for manipulating displayed data or form elements, like checking or unchecking checkboxes, setting different default values etc.

    Enough talking, let’s see sample code for block configuration definition:

    [sourcecode language=”php”]
    class block_yourblock_edit_form extends block_edit_form {
    protected function specific_definition($mform) {

    $mform->addElement(‘header’, ‘general’, ‘Header’);
    $mform->addElement(‘advcheckbox’, "config_checkbox", $repository->name);
    $mform->setType("config_checkbox", PARAM_BOOL);

    $mform->addElement(‘text’, ‘config_text’, ‘Some text input’);

    } // specific_definition

    public function definition_after_data() {
    parent::definition_after_data();

    $mform =& $this->_form;
    $config_text =& $mform->getElement(‘config_text’);
    $config_checkbox =& $mform->getElement(‘config_checkbox’);

    if (isset($config_checkbox->_attributes[‘checked’])) {
    $config_text->attributes[‘value’] = "The checkbox is checked";
    } // if

    } // definition_after_data
    } // class
    [/sourcecode]

    definition_after_data() method must call parent method before start manipulating form data. This method is available in all form classes (see formslib.php in lib directory) and it’s called after definition(), data submission and set_data().

    We found it a great way to manipulate form when form is dependent on the form values or unusual conditions.

    Another useful hint for manipulating group of elements using definition_after_data:

    [sourcecode language=”php”]$group_of_elements =& $mform->getElement(‘some_group_of_elements’)->getElements();[/sourcecode]

    You can also experiment with element visibility, adding css, etc.

    Next Previous
    Moodle+

    Related Post

    • Webinar: Adaptive Learning with Moodle & Totara Learn

      Audrey Colmer | News | 5 October, 2018

      Learning through Moodle or Totara Learn can be made more enjoyable by using adaptive learning methods. Join our webinar to find out more.

    • IntelliBoard Moodle Reporting analytics LMS data

      Webinar: Using IntelliBoard’s Analytics within Moodle to Increase Learners’ Engagement

      Audrey Colmer | News | 3 July, 2018

      Power up your Moodle reporting with IntelliBoard’s real-time analytics.

    • Adaptive Learning with Moodle – Part 3

      Deborah Couedelo | News | 4 May, 2018

      For our final post on Adaptive Learning, we’ll explore different ways to add adaptability to your courses in Moodle.

    • Adaptive Learning with Moodle – Part 2

      Deborah Couedelo | News | 23 April, 2018

      This week, we look at the lesson activity using branches and clusters in Moodle. Part 2/3

    • 5 e-Learning Trends to Watch in 2018

      Mark Melia | Featured News, News | 2 January, 2018

      What are the key e-learning trends we should see in 2018? There are at least 5 of them to remember.

    NextPrevious

    Latest Insights

    • 23 January, 2019
      Comments Off on UX meets Learner Experience meets LMS 2019

      UX meets Learner Experience meets LMS 2019

    • Totara Learn 12
      2 January, 2019
      Comments Off on Webinar: Totara Learn 12 Enhanced Features and Improved Functionality

      Webinar: Totara Learn 12 Enhanced Features and Improved Functionality

    • L&D Trends 2019 Image
      20 December, 2018
      Comments Off on 5 e-Learning Trends to Watch in 2019

      5 e-Learning Trends to Watch in 2019

    • 5 October, 2018
      Comments Off on Webinar: Adaptive Learning with Moodle & Totara Learn

      Webinar: Adaptive Learning with Moodle & Totara Learn

    Archives

    • January 2019
    • December 2018
    • October 2018
    • September 2018
    • July 2018
    • June 2018
    • May 2018
    • April 2018
    • March 2018
    • February 2018
    • January 2018
    • November 2017
    • October 2017
    • September 2017
    • August 2017
    • July 2017
    • June 2017
    • May 2017
    • April 2017
    • March 2017
    • January 2017
    • November 2016
    • October 2016
    • June 2016
    • March 2016
    • February 2016
    • January 2016
    • December 2015
    • November 2015
    • October 2015
    • September 2015
    • July 2015
    • June 2015
    • May 2015
    • March 2015
    • February 2015
    • January 2015
    • December 2014
    • November 2014
    • September 2014
    • June 2014
    • May 2014
    • January 2014
    • August 2013
    • April 2013
    • March 2013
    • February 2013
    • September 2012
    • July 2012
    • May 2012
    • April 2012
    • February 2012
    • December 2011
    • November 2011
    • June 2011
    • May 2011
    • April 2011
    • March 2011
    • February 2011
    • January 2011
    • December 2010

    Sign-up to get our insights direct to your inbox

    Enovation Square

    Enovation Solutions Ltd.,
    T: +44 (0) 2071839207

    Partners & Certifications

    Totara Partner Logo

    Latest Insights

    • UX meets Learner Experience meets LMS 2019

      The ease and intuitiveness which learners are directed to and through learning programmes plays an important role in achieving successful learning outcomes.

      23 January, 2019
    • Totara Learn 12

      Webinar: Totara Learn 12 Enhanced Features and Improved Functionality

      Join our Totara Learn version 12 webinar and explore the enhanced features and improved functionality with us.

      2 January, 2019
    • L&D Trends 2019 Image

      5 e-Learning Trends to Watch in 2019

      It’s that time of year again which can only mean one thing;

      20 December, 2018

    Latest Tweets

    Tweets by @EnovationIRE
    • Legal Information
    © 2019 Enovation Your eLearning Partner
    • WHAT WE DO
      • OUR SERVICES
        • Consultancy
        • Content Creation
        • Build & Design
        • Training
        • Hosting
        • Support & Maintenance
      • OUR SOLUTIONS
        • Moodle
        • The LMS Totara Learn
        • Totara Social
        • Aura Talent
        • Mahara
    • WHO WE ARE
      • About Enovation
      • Careers
    • CASE STUDIES
      • Smyths Toys
      • Tata Chemicals Europe
      • Courts Service of Ireland
      • OpenJaw
      • New College Lanarkshire
    • OUR PARTNERS
      • IntelliBoard
      • BigBlueButton
    • INSIGHTS
    • CONTACT US
    Enovation
    +44 (0)2 0718 39207