In login/signup_form.php, search for:
class login_signup_form extends moodleform {
function definition() {
It should be near the beginning of the file, line 5 or so.
In that function, where it makes sense, add the following lines:
$mform->addElement('text', 'phone1', get_string('phone1'), 'size="20"');
$mform->setType('phone1', PARAM_TEXT);
$mform->addRule('phone1', get_string('missingphone1'), 'required', null, 'client');
$mform->addElement('text', 'institution', get_string('institution'), 'size="40"');
$mform->setType('institution', PARAM_TEXT);
$mform->addRule('institution', get_string('missinginstitution'), 'required', null, 'client');
If they don't already exist, you will want to add language strings in lang/YOURLANG/moodle.php that will return something to the user for missingphone1, missinginstitution, etc.
You should be able to do this with any of the typical user fields - just look at mdl_user in your database to get the proper field name and lengths.
Thanks,
Matt
I am interested in a similar issue with the self registration form. I added to signup_form.php the following:
$mform->addElement('text', 'address', get_string('address'), 'size="40"');
$mform->setType('address', PARAM_TEXT);
$mform->addRule('address', get_string('missingaddress'), 'required', null, 'client');
$mform->addElement('text', 'city', get_string('city'), 'size="20"');
$mform->setType('city', PARAM_TEXT);
$mform->addRule('city', get_string('missingcity'), 'required', null, 'client');
$mform->addElement('text', 'state', get_string('state'), 'size="2"');
$mform->setType('state', PARAM_TEXT);
$mform->addRule('state', get_string('missingstate'), 'required', null, 'client');
$mform->addElement('text', 'zipcode', get_string('zipcode'), 'size="5"');
$mform->setType('zipcode', PARAM_TEXT);
$mform->addRule('zipcode', get_string('missingzipcode'), 'required', null, 'client');
$mform->addElement('text', 'phone1', get_string('phone1'), 'size="20"');
$mform->setType('phone1', PARAM_TEXT);
$mform->addRule('phone1', get_string('missingphone1'), 'required', null, 'client');
$mform->addElement('text', 'cellphone', get_string('cellphone'), 'size="10"');
$mform->setType('cellphone', PARAM_TEXT);
$mform->addRule('cellphone', get_string('missingcellphone'), 'required', null, 'client');
$mform->addElement('text', 'faxnumber', get_string('faxnumber'), 'size="10"');
$mform->setType('faxnumber', PARAM_TEXT);
$mform->addRule('faxnumber', get_string('missingfaxnumber'), 'required', null, 'client');
$mform->addElement('text', 'workaddress', get_string('workaddress'), 'size="40"');
$mform->setType('workaddress', PARAM_TEXT);
$mform->addRule('workaddress', get_string('missingworkaddress'), 'required', null, 'client');
$mform->addElement('text', 'workcity', get_string('workcity'), 'size="20"');
$mform->setType('workcity', PARAM_TEXT);
$mform->addRule('workcity', get_string('missingworkcity'), 'required', null, 'client');
$mform->addElement('text', 'workstate', get_string('workstate'), 'size="2"');
$mform->setType('workstate', PARAM_TEXT);
$mform->addRule('workstate', get_string('missingworkstate'), 'required', null, 'client');
$mform->addElement('text', 'workzip', get_string('workzip'), 'size="5"');
$mform->setType('workzip', PARAM_TEXT);
$mform->addRule('workzip', get_string('missingworkzip'), 'required', null, 'client');
$mform->addElement('text', 'workphone', get_string('workphone'), 'size="10"');
$mform->setType('workphone', PARAM_TEXT);
$mform->addRule('workphone', get_string('missingworkphone'), 'required', null, 'client');
$mform->addElement('text', 'licensenumber', get_string('licensenumber'), 'size="20"');
$mform->setType('licensenumber', PARAM_TEXT);
$mform->addRule('licensenumber', get_string('missinglicensenumber'), 'required', null, 'client');
Now the issue, I am having is that I do not want ALL of the fields to be mandatory, such as the work info fields. How do I make fields optional?
In addition to this issue, after I added these fields to the form I was getting address with [ ]. I am sure that this means that I am doing something wrong.
I tested the form with the config. and the info that I added to the mandatory fields, did not appear in the student profile. We are a school that does continuing education and we need contact info in the event we have issues that need us to contact them.
I added additional info fields to the student profile section for each of the fields in the registration form, but it did not put the data there? Certainly NOT a database person...
Any help in this matter would be appreciated...
steve
$GLOBALS['_HTML_QuickForm_registered_rules'] = array(
'required' => array('html_quickform_rule_required', 'HTML/QuickForm/Rule/Required.php'),
'maxlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
'minlength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
'rangelength' => array('html_quickform_rule_range', 'HTML/QuickForm/Rule/Range.php'),
'email' => array('html_quickform_rule_email', 'HTML/QuickForm/Rule/Email.php'),
'regex' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
'lettersonly' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
'alphanumeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
'numeric' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
'nopunctuation' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
'nonzero' => array('html_quickform_rule_regex', 'HTML/QuickForm/Rule/Regex.php'),
'callback' => array('html_quickform_rule_callback', 'HTML/QuickForm/Rule/Callback.php'),
'compare' => array('html_quickform_rule_compare', 'HTML/QuickForm/Rule/Compare.php')
);
I was not clear on your second question. Does that have to do with language strings? Peace - Anthony
Just remove $mform->addRule lines for those fields that you want to be optional.
Seeing some text inside brackets means that text has no equivalents in language files. go to /lang/{language}/moodle.php and add $string['address']='Address'; to it.
Hi,
I also want to add institution to the self registration form as a mandatory field and I am using moodle 2.6.1.
The couple of lines that I added to login\signup_form is :
$mform->addElement('text', 'institution', get_string('institution'), 'maxlength="100" size="30"');
$mform->setType('institution', PARAM_TEXT);
$mform->addRule('institution', get_string('missinginstitution'), 'required', null, 'server');
Meantime, I declared the new variable in \lang\en\moodle.php:
$string['missinginstitution'] = 'Missing institution';
It works fine if I enter value to the field Institution. If I put blank, since it's a mandatory field, it should show an error message like Missing institution. But I am getting something like this
The interesting thing is, I tried to make changes to some ther variables in \lang\en\moodle.php. But it seems like, that changes do not make any difference in the registration form's error messages. I really would like to know, whether do we have any other file which consists of these messages or else should I make any changes in any other files?
Could any one help me regarding this issue?
Thanks
Sonia
Hi,
have you include require_once($CFG->dirroot.'/lib/formslib.php'); in your forms
Hi,
Thank you for your reply.
But I could see some coding in the file signup_form.php like given below:
require_once($CFG->libdir.'/formslib.php');
require_once($CFG->dirroot.'/user/profile/lib.php');
But still I tried with the piece of code that you mentioned above, but still it is not working
Do you have any other idea what's wrong there?
Thanks,
Sonia