'How to implement placeholder in a php file for moodle plugin?

Hello im new to moodle plugin development and I need to make the "Enter course schedule here..." in the third line disappear when I enter text. If im not mistake it is called placeholder but i dont know how to implement to.

Php code in my own moodle plugin



Solution 1:[1]

Try:

$mform->addElement('text', 'sched_code', 'Schedule Code', ['placeholder' => 'Enter course schedule here...']);

Although, you will want to use get_string() for both bits of text that are being output, rather than hard-coding them like that, so that they can be translated / customised as required.

Solution 2:[2]

Try wrapping the placeholder into [htmlplaceholder tag].

sample HTML placeholder tag

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 davosmith
Solution 2 Willie Cheng