I need to get the value of a parameter of a "mForm" moodle form and do not know how.
I should add the static field "Date Created" to the editing section of a course and not show it as Unix timestamp.
To this had the following:
$fecha_creacion = date('m/d/Y', xxxxxxxxx);
$mform->addElement('static', 'desc' , 'Fecha de Creación');
$mform->setDefault('desc', $fecha_creacion);
where he "xxxxxxxxx" is the integer value obtained from BD in the "mdl_couse" table ('timecreated').
Therefore I need to get the integer value, which is the same parameter that is passed in:
$mform->addElement('static', 'timecreated' , 'Fecha de Creación');
I'm new to moodle. Thank you very much.
Moodle uses HTML_QuickForm so you should be able to consult the documentation at http://pear.php.net/package/HTML_QuickForm/docs/latest/ .
If I understand correctly, in this case you need something along the lines of:
$mform->getElementValue('timecreated');
Hope this helps.
You can pass a parameter to the form
In your edit.php file
// Get the course record that you want.
$course = $DB->get_record('course', array('id' => $id));
// Pass the time created value in an array.
$customdata = array('timecreated' => $course->timecreated);
$form = new edit_form(null, $customdata);
Then in your edit_form.php file
class edit_form extends moodleform {
public function definition() {
$mform =& $this->_form;
// Copy the timecreated value.
$timecreated = $this->_customdata['timecreated'];
// Pass timecreated as the 4th parameter - userdate() will display the date in the users locale.
// You should also use get_string() to display the label in the users language.
$mform->addElement('static', 'timecreated', get_string('timecreated', 'yourpluginname'), userdate($timecreated));
Solution:
$customdata = array('timecreated' => $course->timecreated);
$fecha_c = $customdata['timecreated'];
or
$fecha_c = $course->timecreated;
to get value timecreated
$fecha_creacion = date('d/m/Y',$fecha_creacion);
$mform->addElement('static', 'desc' , 'Fecha de Creación');
$mform->setDefault('desc', $fecha_creacion);
Only in the edition of course:(not for create course)
if (!empty($course->id)) {
$fecha_c = $course->timecreated;
$fecha_creacion = date('d/m/Y',$fecha_creacion);
$mform->addElement('static', 'desc' , 'Fecha de Creación');
$mform->setDefault('desc', $fecha_creacion);
}
Thanks for you help!!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.