Signup form - Add Static Text

Signup form - Add Static Text

by Nano A -
Number of replies: 9

Hello,

First I woudl like to say that I have very little programming knowledge (if any), but I am adventurous so I thought of asking for help to see if I can do this (and learn on the way)

I'm basically trying to add a text below a "user profile field" (menu of choices) - similar to the "passwordpolicyinfo" text that appears above the password field.

I thought that the best way to do it would be to use the text I enter in the description field.  Searching I found this thread below that explains exactly what I want to do and I see that it is has not been resolved yet.

http://tracker.moodle.org/browse/MDL-26343

So far, I have been able to copy this line of code to the appropriate place where I want the code to appear.

$mform->addElement('static', 'passwordpolicyinfo', '', print_password_policy());

Now What I wanted to do is to pickup the text that I have written in the description field to replace the "passwordpolicyinfo" text.

Can someone help me?

Thanks!!! 

 

 

Average of ratings: -
In reply to Nano A

Re: Signup form - Add Static Text

by Tri Le -

Not absolutely sure what you want to do.

But you can replace the print_password_policy function with the text you want to insert. The description may be stored in the global $USER->description

Try this:

global $USER;  // this should be put at the beginning of the function or a file if it hasn't

then, replace your code to

$mform->addElement('static', 'mydescription', '', $USER->description);

In reply to Tri Le

Re: Signup form - Add Static Text

by Nano A -

Thanks for the tip Tri LE.

I did a search in the database and found the text I added in the description box, stored in a table called 'mdl_user_info_field' and the field is called 'description'

What should I change in the code you sent me to call this text?

In reply to Nano A

Re: Signup form - Add Static Text

by Tri Le -

On which page you are modifying? Can you give the URL

In reply to Tri Le

Re: Signup form - Add Static Text

by Nano A -

Not sure if this is what you're asking...

 

In the system, I go to this page to create the 'user profile field'.  In that screen I can create a field with a description.

/user/profile/index.php

 

In the signup form is where I want this 'description' to appear.

/login/signup.php?

 

So the file I am modifying is:

/signup_form.php

 

Does this help?

In reply to Nano A

Re: Signup form - Add Static Text

by Tri Le -

Do you modify the function profile_definition in user/profile/lib.php file?

If yes, the following code should work:
$mform->addElement('static', 'description', '', $field->description);

Because here, you have $field, which is a record in the table already, so $field->description is the description you entered

In reply to Nano A

Re: Signup form - Add Static Text

by Nano A -

Just for anyone else that need to do this.

The solution is very simple.  This is how it was solved - Special thanks to Jenny Gray who was the one that actually did it! smile

I've modified the file 'field.class.php' located inside the field type you want to modify, in my case /user/profile/field/menu/

Then found the function 'profile_field_menu' and added the following line.  

I hope this helps someone wanting to do the same thing.

 
$mform->addElement('static', $this->field->description, ' ',format_text($this->field->description));
 
 
 
In reply to Nano A

Re: Signup form - Add Static Text

by Neil Rhule -

This was absolutely helpful to me. I find it strange that custom fields don't include the ability to add a description field.

In reply to Neil Rhule

Re: Signup form - Add Static Text

by olimpia ricciardi -

Hallo everybody and thanks to who'll answer me.

I added the code in the file user/profile/field/checkbox/field.class.php in the function profile_field_checkbox this way:

function profile_field_checkbox($fieldid=0, $userid=0) {
        global $DB;
        //THIS IS THE LINE I ADDED
        $mform->addElement('static', $this->field->description, ' ',format_text($this->field->description));
        //END OF THE LINE I ADDED
        //first call parent constructor
        $this->profile_field_base($fieldid, $userid);
        if (!empty($this->field)) {
            $datafield = $DB->get_field('user_info_data', 'data', array('userid' => $this->userid, 'fieldid' => $this->fieldid));
            if ($datafield !== false) {
                $this->data = $datafield;
            } else {
                $this->data = $this->field->defaultdata;
            }
        }
    }

It didn't work, this is the error:

Notice: Undefined variable: mform in /var/www/vhosts/mysite.it/httpdocs/moodle/user/profile/field/checkbox/field.class.php on line 13 Fatal error: Call to a member function addElement() on a non-object in /var/www/vhosts/mysite.it/httpdocs/moodle/user/profile/field/checkbox/field.class.php on line 13

Should I do anything else anywhere?

Thank you very much

Lilly