General help

replacing an optional field to required field, please help

 
 
Training
Re: תשובה ל: Re: replacing an optional field to required field, please help
 
Hello Miki,

I did actually manage to figure out making a field required in the edit user form i think. Havent tested it yet tho.

How to make optional form fields a requirement when editing/creating a user (i think, untested)

Edit the file www.mymoodle.com/user/editlib.php around line 237:

Look for this code :

/// Moodle optional fields
$mform->addElement('header', 'moodle_optional', get_string('optional', 'form'));
$mform->setAdvanced('moodle_optional');

$mform->addElement('text', 'url', get_string('webpage'), 'maxlength="255" size="50"');
$mform->setType('url', PARAM_URL);

$mform->addElement('text', 'icq', get_string('icqnumber'), 'maxlength="15" size="25"');
$mform->setType('icq', PARAM_CLEAN);

$mform->addElement('text', 'skype', get_string('skypeid'), 'maxlength="50" size="25"');
$mform->setType('skype', PARAM_CLEAN);

$mform->addElement('text', 'aim', get_string('aimid'), 'maxlength="50" size="25"');
$mform->setType('aim', PARAM_CLEAN);

$mform->addElement('text', 'yahoo', get_string('yahooid'), 'maxlength="50" size="25"');
$mform->setType('yahoo', PARAM_CLEAN);

$mform->addElement('text', 'msn', get_string('msnid'), 'maxlength="50" size="25"');
$mform->setType('msn', PARAM_CLEAN);

// $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
// $mform->setType('idnumber', PARAM_CLEAN);

$mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
$mform->setType('idnumber', PARAM_CLEAN);
$mform->addRule('idnumber', $strrequired, 'required', null, 'client');

$mform->addElement('text', 'institution', get_string('institution'), 'maxlength="40" size="25"');
$mform->setType('institution', PARAM_MULTILANG);

END example code

Then using forward slashes // comment out the code as shown below:
// $mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');

// $mform->setType('idnumber', PARAM_CLEAN);

Now copy and paste the below code just above or below the code you just commented out, or you can simply replace it.
$mform->addElement('text', 'idnumber', get_string('idnumber'), 'maxlength="64" size="25"');
$mform->setType('idnumber', PARAM_CLEAN);
$mform->addRule('idnumber', $strrequired, 'required', null, 'client');

This should now make the field required!!!
If you want to change to max length of the idnumber just change "64", ie "10" or "128" for 10 or 128 characters.

Sorry if i mis-directed you previously.
Regards
Steve
 
Average of ratings: -
Training
Re: תשובה ל: Re: replacing an optional field to required field, please help
 
Testing

I have just tested this, out of interest and found that it works when editing a user profile (when logged in as a student user). Also it works perfectly when creating a new user manually, i have not tried to create an account as a user, but i am definite that will work also.

SO quite happy about that big grin

I'm very pleased to solve your problem Miki, as I say i'm not a PHP coder, but picking it up slowly.

Steve

 
Average of ratings: -
Picture of Miki Alliel
תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
Group Translators

Hi again

thanks I'll check it out today and in the weekend

and I'll let you know if I succeed to do it...

thanks again!

 
Average of ratings: -
Training
Re: תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
 
Hello Miki,

To change the signup form to include the idnumber as the required field insert the red code to the moodle/login/signup_form.php file
Find the below code and around line 50 add the red code

----------------start code------------------
$country = get_list_of_countries();
$default_country[''] = get_string('selectacountry');
$country = array_merge($default_country, $country);
$mform->addElement('select', 'country', get_string('country'), $country);
$mform->addRule('country', get_string('missingcountry'), 'required', null, 'client');
$mform->setDefault('country', '');
//
$mform->addElement('text', 'idnumber', get_string('idnumber'), 'size="25"');
$mform->setType('idnumber', PARAM_TEXT);
$mform->addRule('idnumber', get_string('missingidnumber'), 'required', null, 'client');
//
// buttons
$this->add_action_buttons(true, get_string('createaccount'));
----------------end code------------------

As you have already added the code for making the idnumber a required field, you should not have to do any further changes (i think). The idnumber should now appear of the signup page highlighted in red, if not red then you have not done the code edit in editlib.php

i'm not sure why your description is now required, i can't see how these changes can effect it unless there has been a typo. Perhaps if you double check the field names???

If you post or upload your editlib.php, signup.php and signup_form.php files to the forum I can check them over for you to see where the problem might be.

Let me know how you get on...

Best Regards
Steve
 
Average of ratings: -
Picture of Carrie Goode
Re: תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
 

Hi,

I am using Moodle 1.8 and added a required field region. I used the code above in the signup_form.php as well as the edit.php and have the region field now showing up for new users - however it is showing up with double brackets around the word region  like region any suggestions on what I did wrong?  Also what do you suggest as a learning tool for php? I definately need to learn more. Thanks for any help in advance.

This is what I added to the signup_form

        $mform->addElement('text', 'region', get_string('region'), 'size="25"');
        $mform->setType('region', PARAM_TEXT);
        $mform->addRule('region', get_string('missingregion'), 'required',  null, 'client');

 
Average of ratings: -
Picture of Petr Kalis
Re: תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
 
Hi
String in [] means that you didn't not define this string in your langpack.
Check moodle.php file of langpack you are using (you should let Moodle create local langpack folder for you, check link below), and define this variable (it should like this:
$string['action'] = 'Action';

)

More info about Language editing

Hope this helps.

PK

 
Average of ratings: -
Training
Re: תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
 
HI Carrie,

I hope Petr's advice helped with your missing string?

"Also what do you suggest as a learning tool for php? I definately need to learn more. Thanks for any help in advance."

To be honest, I have always disliked and avoided programming where ever possible, however these days it seems unavoidable for me. So I have accepted that this is not going to change and to just get on with it. Now by that I don't mean I spend hours studying php, but I am a lot more pro-active about finding out what I need to do to get something working (in the programming sense). So I have basically picked up the little php I know from performing many various tweaks and hacks, it does finally start to click and sink in after a while.

I would recommend practising with small code snippets and just 'play' around as much as you can to make your self familiar with php. Of course a linear approach to learning would highly beneficial a good book in particular for beginners is O'Reilly's PHP in a Nutshell by Paul Hudson. Its a very good no nosense book. I have this in a .chm help file format myself for fast referencing, amongst a few other ebooks/.chm files, but these are mainly for technical reference more so than an explaination of 'how to do'.

Hope it helps.
Steve
 
Average of ratings: -
Picture of Miki Alliel
תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
Group Translators

Hii

well I tried it and it does make it required but' it is now displayed with the green and red star together.

Anyway, suddenly when a user want to edit the profile within the idnumber he must add to the "description" field something too which was empty from the beginning. Which mean that the description field is also required and now actually we don't want it to be alert when they edit their idnumber. How do I delete a required filed? Or How do I delete this discretion Field so it won't be a required one? Where it is not even a must fill in Field in the signup.php page only when you edit your profile it suddenly alert you to edit this field .

 
Average of ratings: -
Picture of vikas deoarshi
Re: תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
 
Can anybody help me in this :
hi i want to insert feedback from and conatact froms . is there any way that i can use moodle internal sending script for it . plz guide




 
Average of ratings: -
Training
Re: תשובה ל: Re: תשובה ל: Re: replacing an optional field to required field, please help
 
Hello Vikas,

You can use the "feedback" module to accomplish this for feedback. This module allows you to create custom feedback questions and is a good improvement on the survey module.
There is also a contact us module I believe AND I would reccomend using the Ask a Question module - which allows the user to click which tutor/contact they want to send the email too.

You could always use a none integrated contact form which you can probably pick up from http://www.dynamicdrive.com or other similar website. Also there is a nice one called PHmailer I use and have restricted access so a user has to be logged in to use the form. This is very loosely integrated and still asks for the senders email address - so this is good for none members. You can get phmailer from http://phphq.Net, Custom PHP Scripts :- Script Name: phMailer

Steve



 
Average of ratings: -