Forms API

Forms API

by Marco Cigna -
Number of replies: 6

G'day,

Is it possible to change the default moodle sitesupport template, to a more aesthetic one without impacting the core functionality of it i.e. it would still be able to clean the text inputs?

I've had a look at setting up a separate plugin to act as a sitesupport page (as I really don't want to edit the existing one ~ Looks a bit of a mess) but I am unsure how to incorporate the mustache template with "PARAM_TEXT" cleaning functionality. As of now it looks as it is incorporating the default mustache template:

Template I want to use is as below:


Unfortunately, as default html this doesn't have any cleaning functionality which is desirable for security reasons.

Any help is appreciated!

Average of ratings: -
In reply to Marco Cigna

Re: Forms API

by lior gil -
Picture of Core developers
This can actually be done with CSS. You can manipulate this form to be visually similar to what you want. Even the added text at the top, as long as you don't need to support another language.
Tough, there is a cost. You'll need to check it after every version update, even a minor one, to make sure it doesn't break anything.
In reply to lior gil

Re: Forms API

by Marco Cigna -
There is a lot of CSS to override to change the look of the page. What about editing the mustache template itself? Where would that be located and would that impact any other forms in Moodle?
In reply to Marco Cigna

Re: Forms API

by lior gil -
Picture of Core developers

There's no template, this form is built by the standard form API.

I tried playing with the CSS and got halfway there, so if you're interested you can take it from there in the attached file.

Note that I kept the subject input as well as the labels, because even though you prefer not to use them they do have purpose and should not be removed.

Personally I would advise not to deviate too far from the form structure.

Average of ratings: Useful (1)
In reply to lior gil

Re: Forms API

by Marco Cigna -
Appreciate the response and the sample css you have provided, it has helped me greatly!
In reply to lior gil

Re: Forms API

by Graicelys Volcán -
Hello, I have a question. I am trying to modify a form and add external classes for css, and I call the file in css by a link

$mform->addElement('textarea', 'contentuser', get_string('usercontent', 'local_laika'));
    $mform->setType('contentuser', PARAM_TEXT);
   
    // Enviar.
    $submitlabel = get_string('submit');
    $mform->addElement('submit', 'submitmessage', $submitlabel);

    // Agregar una clase CSS al formulario
   $mform->updateAttributes(array('class' => 'chat-form'));

    // Agregar una clase CSS al campo contentuser
    $mform->getElement('contentuser')->updateAttributes(array('class' => 'chat-form-contentuser'));
    $mform->getElement('submitmessage')->updateAttributes(array('class' => 'chat-form-submit'));

    echo"<link rel='stylesheet' type='text/css' href='form.css'>";
 }
}


But I realize that it does not modify everything as such, so I separate by class, so far the only one I have taken was chat-form, but the others do not take the css, or is it that it cannot be done like this?
In reply to Graicelys Volcán

Re: Forms API

by Dominique Palumbo -
Picture of Particularly helpful Moodlers Picture of Plugin developers
Hi,

Maybe you can try to add at the top of your function this call with the right path $PAGE->requires->css('path/form.css');

Dominique.