+353 (0)1 602 4784
info@enovation.ie
  • Client Support
  • FR
  • PL
EnovationEnovationEnovationEnovation
+353 (0)1 602 4784
  • WHAT WE DO
    • OUR SERVICES
      • Consultancy
      • eLearning Content
      • Build & Design
      • Training
      • Moodle Educator Certification Program (MEC)
      • Hosting
      • Support & Maintenance
    • OUR SOLUTIONS
      • Aura Talent
      • Aura Perform
      • Moodle
      • Moodle Workplace
      • Totara’s Talent Experience Platform
        • Totara Learn
        • Totara Engage
        • Totara Perform
      • Mahara
  • WHO WE ARE
    • About Enovation
    • Careers
  • CASE STUDIES
  • OUR PARTNERS
    • Microsoft Teams
    • 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

    Audrey Colmer | 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

    • Reflections on MEC Webinar Wednesday May 11th at 12:00UTC.

      Enovation Admin | News | 6 May, 2022

      Learn all about Moodle with free online courses Develop your career as a Moodle Educator, Administrator, Designer and Developer and learn all about online education with Moodle. Sign up to webinars, complete courses and getRead more

    • Enovation Sponsor The HEAnet 2022 Conference

      Enovation Admin | News | 2 March, 2022

      7 days to go! We are delighted to be sponsoring The 2022 HEAnet Conference.  The Conference is taking place on the 09th – 11th March 2022 in the Great Southern Hotel, Killarney. HEAnet is Ireland’s NationalRead more

    • Moodle on Mobile Update

      Enovation Admin | News | 14 February, 2022

      https://moodle.com/wp-content/uploads/2020/12/Moodle-App576.mp4 Although Moodle can work perfectly well on mobile browsers, there are times when an app provides a better experience on mobile devices. In order to give your learners mobile-native experiences like offline access andRead more

    • 4 Ways to Create Engaging Training

      Enovation Admin | News | 16 November, 2021

      According to Christine Fröhlich (Digital Learning Officer at Enovation), there are 4 ways to apply to attract and maintain the attention of learners.  Moodle LMS makes it possible sustain to these principles with ease. Find out the 4 ways to create engaging training.

    • Webinar is written on a notepad with Enovation and Brickfield Education Labs logos underneath.

      Webinar: Lunchtime Learning – Moodle Accessibility

      Enovation Admin | News | 8 November, 2021

      Brickfield Education Labs are one of our partners, and their Moodle Accessibility Toolkit is a Certified integration for Moodle. In this session, Gavin shared his knowledge and experience in this area because it is somethingRead more

    NextPrevious

    Latest Insights

    • 26 July, 2022
      Comments Off on Not quite ready for OKRs?

      Not quite ready for OKRs?

    • 27 June, 2022
      Comments Off on #ILC2022 with EASL and Enovation

      #ILC2022 with EASL and Enovation

    • 16 June, 2022
      Comments Off on Webinar: Transforming Teaching & Learning through Microsoft 365 & Enovation on Moodle

      Webinar: Transforming Teaching & Learning through Microsoft 365 & Enovation on Moodle

    • 8 June, 2022
      Comments Off on Webinar with OpenSesame: The Strategic Role of Learning and Development in DEI

      Webinar with OpenSesame: The Strategic Role of Learning and Development in DEI

    Archives

    • July 2022
    • June 2022
    • May 2022
    • April 2022
    • March 2022
    • February 2022
    • January 2022
    • December 2021
    • November 2021
    • October 2021
    • September 2021
    • August 2021
    • July 2021
    • June 2021
    • May 2021
    • April 2021
    • March 2021
    • February 2021
    • January 2021
    • December 2020
    • November 2020
    • October 2020
    • September 2020
    • August 2020
    • July 2020
    • June 2020
    • May 2020
    • April 2020
    • March 2020
    • January 2020
    • November 2019
    • October 2019
    • September 2019
    • August 2019
    • July 2019
    • June 2019
    • May 2019
    • March 2019
    • February 2019
    • January 2019
    • December 2018
    • November 2018
    • October 2018
    • September 2018
    • August 2018
    • July 2018
    • June 2018
    • May 2018
    • April 2018
    • March 2018
    • February 2018
    • January 2018
    • December 2017
    • 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
    • January 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.,
      The Friary,
      Bow Street,
      Dublin, D07 X680,
      T: +353 (0) 1 602 4784

      Partners, Awards & Certifications

      Moodle Partner Logo

      Latest Insights

      • Not quite ready for OKRs?

        Consider using the simpler MSC framework deployed using Enovation’s Aura Perform solution

        26 July, 2022
      • #ILC2022 with EASL and Enovation

        International Liver Congress™ 2022 EASL’s International Liver Congress™ in London was a

        27 June, 2022
      • Webinar: Transforming Teaching & Learning through Microsoft 365 & Enovation on Moodle

        Join Enovation and Microsoft Education for a webinar on how your tools

        16 June, 2022

      Latest Tweets

      Tweets by @EnovationIRE
      • Legal Information
      © 2022 Enovation Your eLearning Partner
      • WHAT WE DO
        • OUR SERVICES
          • Consultancy
          • eLearning Content
          • Build & Design
          • Training
          • Moodle Educator Certification Program (MEC)
          • Hosting
          • Support & Maintenance
        • OUR SOLUTIONS
          • Aura Talent
          • Aura Perform
          • Moodle
          • Moodle Workplace
          • Totara’s Talent Experience Platform
            • Totara Learn
            • Totara Engage
            • Totara Perform
          • Mahara
      • WHO WE ARE
        • About Enovation
        • Careers
      • CASE STUDIES
      • OUR PARTNERS
        • Microsoft Teams
        • IntelliBoard
        • BigBlueButton
      • INSIGHTS
      • CONTACT US
      Enovation
      +353 (0)1 602 4784