Following the madness of a Moodle developer
I started my first module creation.
I found all I needed to start with module creation but not the same about moodle forms.
I tried to look inside moodle glossary php code and I found something but... which one is the API I have to browse in order to be more confident with moodle forms?
I would like to learn what is the minimum to start, how to create a "fixed" block of field to add to a different generic form (as Moodle already does), how to add a check box close to a field to see the password and not asterisks (as Moodle already does), how to, how to, how to...
Where have I to go?
Thank you in advance
I've always used the following wiki page and the others in the formslib category:
http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition
http://docs.moodle.org/en/Development:lib/formslib.php_Form_Definition
woooow - thanks... this is what i also needed!
Thank you Adam.
I believe this is what I need.
I believe this is what I need.
Hei Adam
I found a more general index page for Formslib.
http://docs.moodle.org/en/Category:Formslib
Thank you again.
I found a more general index page for Formslib.
http://docs.moodle.org/en/Category:Formslib
Thank you again.
I am trying to create a standard moodle form displaying just a field.
By pressing the submit button what I expect is to ALWAYS return to the form page showing a feedback like... "you entered <<field_content>>"
AND
with the field of the moodle form EMPTY.
To get this I changed the standard explanation provided in doc.moodle.org by changing
$mform = new yourmod_formfunction_form();//name of the form you defined in file above.to
if ($mform->is_cancelled()){
} else if ($fromform=$mform->get_data()){
} else {
$mform->set_data($toform);
$mform->display();
print_footer($course);
}
$mform = new yourmod_formfunction_form();//name of the form you defined in file above.
if ($mform->is_cancelled()){
} else if ($fromform=$mform->get_data()){
} else {
}
$mform->set_data($toform);
$mform->display();
print_footer($course);
My problem is that whenever I get the form for the second time I always get the field STILL WITH the text I entered.
I even added the $mform->setDefault('field','defaultvalue'); but it defines the defualt of the new empty form... not of the re-loaded form.
Who can I dispose of the text I entered at the reload time?
Thank you in advance.
Hi,
You can use :
$mform->setConstants(array('field'=>'defaultvalue'));
Jamie
You can use :
$mform->setConstants(array('field'=>'defaultvalue'));
Jamie
Fantastic. Thank you.
Do you believe me if I tell that... I spent two evenings (more or less, 6 hours) trying to get the right solution.
Thank you, Jamie.
Am I wrong if I say that... setConstants is not deeply described in docs.moodle.org?
Do you believe me if I tell that... I spent two evenings (more or less, 6 hours) trying to get the right solution.
Thank you, Jamie.
Am I wrong if I say that... setConstants is not deeply described in docs.moodle.org?
Reading the documentation provided in http://docs.moodle.org/en/Category:Formslib
I am able to add a read only field to a form only with:
In this way I leave to the remote user the idea that... the field is available and he/she has only to find a way to enable it.
So I would like to show the content of my 'currentstatus' field using a static text like the one I can get using:
but... it doesn't work.
I also tried:
but it still doesn't work.
What am I supposed to use?
Sorry If I always ask.
Thank you in advance.
I am able to add a read only field to a form only with:
$mform->addElement('text', 'currentstatus', get_string('currentstatus_label', 'newmodule'), array('disabled'=>'disabled'));
So I would like to show the content of my 'currentstatus' field using a static text like the one I can get using:
$mform->addElement('static', 'description', get_string('currentstatus_label', 'newmodule'), currentstatus);
but... it doesn't work.
I also tried:
$mform->addElement('hidden', 'currentstatus', 'currentstatus');
$currentstatus = $mform->getElementValue('currentstatus');
$mform->addElement('static', 'description',
get_string('currentstatus_label', 'newmodule'), '$currentstatus');
$currentstatus = $mform->getElementValue('currentstatus');
$mform->addElement('static', 'description',
get_string('currentstatus_label', 'newmodule'), '$currentstatus');
but it still doesn't work.
What am I supposed to use?
Sorry If I always ask.
Thank you in advance.
"So I would like to show the content of my 'currentstatus' field using a static text"
Isn't the content already visible in the text box?? It should be although the text box is disabled.
Isn't the content already visible in the text box?? It should be although the text box is disabled.
Yes it is, but, IMO, it is not so nice to see in a text box... because it seems you can edit it even if this is not true.
I am trying to build a mform to import a zipped folder.
Once the user push the submit button I want to start the following check.
// 1. It selected file has to be a zip file
// 2. The zip file has to contain only a folder (or only folders if more than ht per time is imported)
// 3. The folder has to have a name not present in the repository of files of this user and course
To build the form I added:
$mform->addElement('file', 'zippedfoldertoupload', get_string('attachment', 'forum'));
$mform->addRule('zippedfoldertoupload', null, 'required');
in the function definition() of the class
class mod_newmodule_uploadzip_form extends moodleform {
To perform the validation I was thinking to use the function validation($data) {
At this point I have three problems:
1: why do inside the function "validation" it is not defined the array item: $data('zippedfoldertoupload')?
If I change
$mform->addElement('file', 'zippedfoldertoupload', get_string('attachment', 'forum'));
$mform->addRule('zippedfoldertoupload', null, 'required');
to
$mform->addElement('text', 'zippedfoldertoupload', get_string('attachment', 'forum'), null);
in the function validation($data) { the array item: $data('zippedfoldertoupload') is well defined.
Is this a bug?
2: How am I supposed to use the
$this->set_upload_manager(new upload_manager('httoimport', true, false, $COURSE, false, 0, true, true, false));
What does each parameter, passed to upload_manager(), mean?
What is this class suposed to do?
3. which function (array element ??) does return me the path of the selected file inside the function validation($data)?
I am sorry for this questions but I was not able to find their answers in moodledocs.
If you know them in moodledocs, simply redirect me to them on the web.
TIA
Once the user push the submit button I want to start the following check.
// 1. It selected file has to be a zip file
// 2. The zip file has to contain only a folder (or only folders if more than ht per time is imported)
// 3. The folder has to have a name not present in the repository of files of this user and course
To build the form I added:
$mform->addElement('file', 'zippedfoldertoupload', get_string('attachment', 'forum'));
$mform->addRule('zippedfoldertoupload', null, 'required');
in the function definition() of the class
class mod_newmodule_uploadzip_form extends moodleform {
To perform the validation I was thinking to use the function validation($data) {
At this point I have three problems:
1: why do inside the function "validation" it is not defined the array item: $data('zippedfoldertoupload')?
If I change
$mform->addElement('file', 'zippedfoldertoupload', get_string('attachment', 'forum'));
$mform->addRule('zippedfoldertoupload', null, 'required');
to
$mform->addElement('text', 'zippedfoldertoupload', get_string('attachment', 'forum'), null);
in the function validation($data) { the array item: $data('zippedfoldertoupload') is well defined.
Is this a bug?
2: How am I supposed to use the
$this->set_upload_manager(new upload_manager('httoimport', true, false, $COURSE, false, 0, true, true, false));
What does each parameter, passed to upload_manager(), mean?
What is this class suposed to do?
3. which function (array element ??) does return me the path of the selected file inside the function validation($data)?
I am sorry for this questions but I was not able to find their answers in moodledocs.
If you know them in moodledocs, simply redirect me to them on the web.
TIA
Thanks Jaime. Ciao.
Sorry Jamie if I still ask.
At the bottom of
At the bottom of
http://docs.moodle.org/en/Development:lib/formslib.php_ValidationI found:
$errors = parrent::validate($data, $files);Following the outcome of my investigation I believe that...
parrent
needs to be changed toparent
(And I already did it as you should know)validate
should be replaced byvalidation
but I am not brave enough to change it by myself. Am I right?
Right on both counts Daniele, thanks.
Updated. Thanks to you.