I am creating a database using database module and would like to insert user name into one of the database field automatically (I don't want students to put in themselves) but I have no clue how to do this. I only managed to show the username in Add Entry form but not able to add that into database.
I had tried many ways myself but obviously to no avail. Thanks in advance for any help.
'adding to the list view some commented out lines which when activated (and the others commented out', pardon me for not able to get the point. Are you able to illustrate more on this hack ?
Yes and sorry. This is not a hack but rather an alternative way to think about the list view of the database. Suppose that your database displays a list of person-hobby pairs such that the person is the one entering the info. So your database would have a hobby field and the name of the person will be displayed by means of the ##user## field. Now, typically the list view template would be set as a table and look like this (simplified):
<table border="1" cellpadding="5">
<tbody>
<tr>
<th>Name</th>
<th>Hobby</th>
</tr>
body
<tr>
<td>##user##</td>
<td>||hobby||</td>
</tr>
footer
</tbody>
</table>
(|| stands for square brackets)This table with two entries should display the following:
Name | Hobby |
---|---|
John Doe | Snowboarding |
Jane Doe | Hang-gliding |
You can add the following commented out lines (bold only for emphasis):
header
<table border="1" cellpadding="5">
<tbody>
<tr>
<th>Name</th>
<th>Hobby</th>
</tr>
<!--
Name,Hobby<br />
-->
body
<tr>
<td>##user##</td>
<td>||hobby||</td>
</tr>
<!--
##user##,||hobby||<br />
-->
footer
</tbody>
</table>
So far there is no change to the display. However, if you switch the comment tags position to comment out the table:
header
<!--
<table border="1" cellpadding="5">
<tbody>
<tr>
<th>Name</th>
<th>Hobby</th>
</tr>
-->
Name,Hobby<br />
body
<!--
<tr>
<td>##user##</td>
<td>||hobby||</td>
</tr>
-->
##user##,||hobby||<br />
footer
<!--</tbody>
</table>
-->
The display will change to:
Name,Hobby
John Doe,Snowboarding
Jane Doe,Hang-gliding
which you can copy and paste into a text file, change the .txt extension to .csv and open with Excel.
Hope this helps.
However users of database, the teachers, are not comfortable with the html handling. So I added additional field in database just to store student names as alternative solution at this moment.

Just spotted this thread. Users of 1.9 might be interested in this patch which addresses the original problem:
http://tracker.moodle.org/browse/MDL-22773
Steve