Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-31677

Class moodleform should support underlying QuickForm->toHtml()

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Duplicate
    • Affects Version/s: 2.1, 2.2, 2.2.1
    • Fix Version/s: None
    • Component/s: Forms Library
    • Labels:
    • Testing Instructions:
      • Make a form definition.
      • Try rendering echo $form->html(); or $form->display();
      • Behavior should be the same.
    • Workaround:
      Hide

      The current workaround is using reflection to retrieve the protected {_form} property. This is a nasty hack.

      $reflect = new ReflectionClass('my_moodleform');
      $form_field = $reflect->getPropert('_form');
      $form_field->setAccessible(true);
       
      $html = $form_field->getValue($form)->toHtml();

      Show
      The current workaround is using reflection to retrieve the protected { _form } property. This is a nasty hack. $reflect = new ReflectionClass('my_moodleform'); $form_field = $reflect->getPropert('_form'); $form_field->setAccessible(true);   $html = $form_field->getValue($form)->toHtml();
    • Affected Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE

      Description

      There are cases where the developer needs the form html instead of immediate display. This behavior would be consistent with $OUTPUT and html_writer.

      // Returns html of form
      $html = $form->html();

      I have included a patch that adds this behavior.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              moodle.com moodle.com
              Reporter:
              pcali1 Philip Cali
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: