Forms API

Forms API

Marco Cigna -
回帖数: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!

回复Marco Cigna

Re: Forms API

lior gil -
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.
回复lior gil

Re: Forms API

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?
回复Marco Cigna

Re: Forms API

lior gil -
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.

回复lior gil

Re: Forms API

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?
回复Graicelys Volcán

Re: Forms API

Dominique Palumbo -
Particularly helpful Moodlers的头像 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.