OK I have tried to add it. I would appreciate you testing it. It seems to work for me but my testing is a bit contrived (and these changes further test the differences between standard blocks and my implementation).
This should allow the block to be displayed on the main site index page along with course pages of weeks, topics and social formats. If the request/comment from froms the main site index page the email goes to the site admin only. If the request/comment comes from a course page the email should go to the site admin and also to every registered teacher of that course.
If it works for you I will add a cross post in the other forum to note the newer package here.
Hi Daryl,
I saw the post from the other discussion first and posted there, only to read further in my email and see this thread and find that Art had beat me to the punch regarding adding this to a course.
I just tested this script--when I hit the continue link I got the That's an invalid course id error. Also, I only received one email to the admin address, and not one to the teacher's email address. Other than that it worked.
Here's another suggestion: Have you seen Jan Dierckx random quote block--(http://moodle.org/mod/forum/discuss.php?d=10851) he has added the ability to change the settings for a block. For example you can change the block name. This way, on the sitepage the block could be named Leave a Comment, and within a course it could be named "Ask a Question". Then the submit value could be a generic one. (Not sure if you would be able to have a different submit value for each block (or a different email message).
Chardelle
It was 25. I have changed it to 20 with the files in update 4. If you would like to try other values open the file block_contact_form and edit the size value on the line that matches this:
$this->content->text .= '<input type="text" name="name" size="20" /> <br />';
Hi Daryl and n,
It appears that my site is not picking up on the "if in a course" part of the code and that is why I am having the above problems. I realized this when after looking at the code I noticed that one of you had added a different title (Ask a Question) if in a course. When I add the block to a course, it still comes up as Contact. So..... that's what is happening, the question remains as to why.
Chardelle
This one attempts to resolve the id=Object link you are seeing.
It has different titles for the site page versus the course pages: Leave a Comment and Ask a Question. The form submit button is now the generic text - "Submit".
I added an extra as well to match the way the blog comments work. If the user is logged in the name and email fields for the form are pre-populated.
Happy testing - moodle on....
Yep,
Works great. Our teachers will like it a lot, I think.
(The only thing that is a little odd is that clicking on "continue" does not now cause an error message, but does cause you to leave the course and go to the front page of the site.)
Thanks!
-- Art
I'd like to add some more comments, now that I have installed the block.
1-If you are logged into your site, the "submit" button is not centered in the block. I do like the way it fills in the name and email automatically.
2-If you are not logged into the site, there are layout issues-a box is displayed inside a box in the block. The submit button is not centered.
3-It is quite illogical to expect people to enter their name and then click "submit" before getting to the full form. No website comments form elsewhere works like that and people are going to be put off by it. Why should they have to give their name first before seeing the form? Either you ask them for nothing at all or you ask them for everything up front, which would take too much space.
4-Comment number 3 is why I originally envisioned this as an activity, and why I posted it in the module forum, not the block forum. You could link to it from the site menu, or you could link to it from inside a course. There are certain things that are more appropriate as activities and others more appropriate as blocks, and I think this is one of the former. A block should be used for something that as a whole should take up a limited amount of space.
I hav edownloaded this and it is working great on my site main page. However, it is not appearing at all in my available blocks on the course pages. Any ideas on how I get it included there as well?
Also, when the thankyou page comes up it includes the characters and at the beginning and end of the message and at the beginning anf end of the continue link. I tried to find this in the code but could not - any ideas on how I can take these characters out?
As for adults, the reason this problem came to my attention is because I received a rather nasty email (nasty about a third party, not me) in response to a discussion I had been having on another board that involved the third party, from some anonymous person who sent it to me through the contact form. Because they clicked through the resource link, I was able to tell what their ip address was, but that wouldn't have happened if I had a direct link. And more importantly, this certainly was an adult who sent it, because there aren't any children on said board and I traced their ip to a certain American unversity. Don't think that adults aren't capable of harrassment.
The only difference is that using the tell a friend script the same student could send hundreds of them with a single mouse click.
(I am kind of hoping that this would be the difference between adults and kids: the former quitting after having sent one email.)
Configure your v1.5 contact block and enable the CC Admin option. This is not new code, it's been there in the 1.5 version since it was put in contrib.
So the contact form block now logs the user's IP address and can optionally CC the site administrator on all messages. Anything it's missing?
For Nicole I have added logging - now when someone sends a message with the form their ip address along with to/from and the subject get logged.
For Nikki I have fixed the applicable formats so that it should now appear in courses again (this block was ready before 1.5 went final and Jon made a small feature tweak along the way which I had to correct for).
Also Nikki - are you sure that you copied the lang/en contents into your moodle/lang/en folder? The "blah" output you are seeing means that a translation for a string cannot be found and I verified that all the strings thanks.php looks for are present in lang/en/block_contact_form.php
I now have the contact block on my course pages as well which is brilliant. one small thing I would like to change though, just not sure how I do it.
The email sent from teh course page currently goes to all the teachers for that course. I would like to amend it so it only goes to the teacher assigned for the group the student is in. Otherwise the teachers are going to get hundreds of emails from students they are not looking after.
I had a look and can see where the code looks up the teachers assigned to the course. I was thinking I would need to do something like:
- find the teachers for the course (as is done now)
- find the group id for the courseid
- find the group id for the student
- find the group id for the teachers
- send the teacher the email when the group id for the student and the group id for the teacher match
Does this sound right? I had a go but the coding is just too complex for me! Any ideas welcomed!
One other thing. The contact form seems to be working without producing any errors but when I go to the admin page it gives me an error message:
"Version mismatch: block contact_form can't downgrade 2004102400 -> 20050701!"
Is there anywhere that I can find the correct version of the block so I do not get this error?
Thanks, Nikki
The email sent from teh course page currently goes to all the teachers for that course. I would like to amend it so it only goes to the teacher assigned for the group the student is in. Otherwise the teachers are going to get hundreds of emails from students they are not looking after.
[...]
Does this sound right? I had a go but the coding is just too complex for me! Any ideas welcomed!
It sounds right to me. The only thing I would add then is on the config form add an option for "teachers in user's group". If the course allows anonymous access the guest user may not be in any group of course.
"Version mismatch: block contact_form can't downgrade 2004102400 -> 20050701!"
Is there anywhere that I can find the correct version of the block so I do not get this error?
Thanks for pointing this out. I made a mistake in updating the version number for the block on the last fix. I have sent a change in to cvs contrib. If you would simply like to edit your file modify block_contact_form.php to say version 2005070100 instead of 20050701.
I'd just like to report a little bug - when I try to change a setting via the configuration --> modules page, I get the following error message:
Sorry, but your session key could not be confirmed to carry out this action. This security feature prevents against accidental or malicious execution of important functions in your name. Please make sure you really wanted to execute this function.
This occurs when trying to change any of the settings on that page.
Tim.
config_global.html new revision: 1.3
config_instance.html new revision: 1.2
form.html new revision: 1.2
thanks.php new revision: 1.3
<input type="text" name="subject" size="25" maxlength="200" <?php if( isset($subject)){ echo 'value="'. $subject .'"';}?>/>
with your drop down menu line - something like the following untested pseudocode:
<?php
$options = array('Technical Support' => 'Technical Support', 'Ask the Teacher' => 'Ask the Teacher', 'Ask the TA' => 'Ask the TA', 'Comment' => 'Comment');
choose_from_menu ($options, 'subject');
?>
Instead of nameOfTheSite >> nameOfTheCourse >> contact_form the user only gets nameOfTheSite >> contact_form. How can it be corrected?
Is it possible to have a way to select in the form the teacher to contact? Something like what you proposed for the subject field?
Thank you in advance.

Hi Daryl,
I tried to install the block.
I got an error.
Warning: file(c:\program files\easyphp1-7\www\moodle/blocks/__MACOSX/block___MACOSX.php): failed to open stream: No such file or directory in c:\program files\easyphp1-7\www\moodle\lib\blocklib.php on line 21
Can you help me resolve this.
I must have gone wrong somewhere,
Garry
I have been out most the day working on a Discussion for class. The development of this block/module has been amazing. "N" stirred it and "Daryl" cooked it.
Just a few thoughts [Some which may seem more than necessary. Also they may be looked at as future features.]
- The contact feature should be
- A block with a link that can be placed on the site page and
into individual courses along with the blog page Daryl, of course.
, AND/OR
- A link which can be added near the bottom of the site menu block via some type of toggle switch [similar to the new topic feature] from the Site Settings page. This should also be handled in a course vis the Course Settings page. This instead of an entire separate block. OR
- A block with a "dropdown" menu of contacts, textarea.
- A block with a link that can be placed on the site page and
into individual courses along with the blog page Daryl, of course.
- There should be an option to have the Contact form display as a
- PopUp Window [If as a popup, there should be some text to
indicate that is what the link is going to do so popup blockers can be
disabled for this], OR
- As a module.
- PopUp Window [If as a popup, there should be some text to
indicate that is what the link is going to do so popup blockers can be
disabled for this], OR
- The Contact form should have a "dropdown" menu allowing the student and teacher to contact neccessary folk *,
- Teacher - Admin, Tech Help, Other Teachers in the Course [Individual / Group], Other Teachers on the Site [Individual / Group], etc...
- Student - Admin, Tech Help, Teachers [Individual / Group], etc...
- The ability to place an address and telephone number and fax number might also be nice on the form as well.
- The email addresses should not be readable by a search "spider".
I think Martin and Mike have some code from the MoodleWiki to deal with this.
- E-mail address of the sender
- Course participant - should be automatically placed in the contact form.
- Site Visitor - Area to place e-mail address.
- Course participant - should be automatically placed in the contact form.
* I am dealing from a purely educational view here. The Business people might need descriptions such as, Admin, Sales, WebMaster, Inquiry, HelpDesk. A GUI dealing with all this might be helpful.
The contact form by NukeStyles.com [Yes, I know one of those phpNUKE script sites, but, a very good one] has a nice contact script. I will post an image for an example of some of the things I am referring to.
Alas, I am tired now because of so much work I did for the Contact feature!!!
WP1

I thought I heard little elves tapping away in the night.
Thanks n, it appears you have answered all of the issues except for one. When added to a course, the code does not pick up the teacher's email address, it is still sent to the admin address. Daryl, did you ever get this worked out?
Also, when added to a course, I myself would delete the "Us", since for a course with only one teacher/facilitator the "Us" makes no sense. (Like I mentioned above, it would be nice to be able to have a different submit value for each block--e.g. Send Us an Email, Ask-a-Question, Submit a Comment...but like I said, not sure if this would be possible?????) Maybe this differentiaiton issue could be addressed somehow with WPs drop-down menu idea above.
Thanks you guys
Chardelle
It appears I did not get the teacher email problem worked out. As far as I can tell the code is OK and it sends email to both the admin and the teacher on my test site as of update 4. There might be some case I am unaware of though which would cause it to fail on your site (?)
Regarding custom text for the submit button - just use a link instead. In n's first post there was a readme file that outlined how to make a link to the contact form from the site front page. The block is just a button doing the same thing rather than a link (I had wanted to put the full form there, but it doesn't fit well in that context).
In the short term I suggest installing the block but not adding it to your site/course. Instead add a new activity/resource link. In addition you could modify the moodle footer.
The link you create should simply point to the form.php file - so yoursite.com/moodle/blocks/contact_form/form.php is the link substituting your url to moodle
Original instructions:
*In your Main Menu on your site, choose "Add a resource" and then "Link to a file or Web site."
*In the "Summary," type the text you want to appear before the feedback form.
*In "Location," enter the path to form.php.
*Choose "Same window" and then "Save Changes."
*Your form should now work.
Hi Daryl,
Yes, adding it as a link instead of a block on the site homepage is probably the best way to go. But, it needs to be added as a linked label, like n suggested, because it is picking up the theme. If you add it as a resource link, then it brings up the theme with the form so you end up with a header above the form giving you two headers on the page.
Now, as for adding it to a course. Still not quite there yet, maybe someone else can test it to see if they get an email to the teacher's email address-I just don't and haven't figured out why yet. Also, after submitting, and then clicking continue, it takes you back to the site homepage, rather than back to the course homepage. (By the way, I am using version 5 that n posted above.
Chardelle
http://www.mysite.com/blocks/contact_form/form.php?subject=Course Suggestion
Then it automatically fills in the subject field.
Great tricks n,
I don't know why I didn't try setting it to no frames. That works great. And the subject field idea is a good one also. But, I still would like to get the within a course code working. Especially as a way for students to easily send a message if they are having problems. I wouldn't use the dialogue for this for these reasons. 1) It is better to have this link in a block--and be separate from course content--rather than stuck somewhere within a topic. 2) I think that the dialogue module would be too inviting for students to feel they can continue and on-going dialogue with a teacher (and thus take up too much of the teacher's time). The way my courses are setup, the dialogue feature is reserved only for those who pay to have a one-on-one dialogue--not for general use. A better alternative than dialogue is to set up a FAQ glossary. But I still like the Ask-A-Question idea the best--just need to get it working.
Chardelle
1. Regardless of whether someone is logged in or not, or whether they have chosen to keep their email address private, the "From" address used by the Contact Form is the default noreply address set in the Config->Variables page. It would be helpful if this could be set to show the email address of the sender.
2. When the form is submitted, the "Continue" link points to http://domain/course/view.php?id=1 - which forces the log in page in you're not logged in. It would be helpful if this could just return to the site main page (or even better would be a configurable 'return to' page).
3. The code in block_contact_form.php suggests that the name of the block is different depending on whether the block is on the front page or within a course...
function CourseBlock_contact_form($course) {
if(!isset($course) || $course != 1){
//we're displaying on the site page
$this->title = 'Contact Us'; //get_string('activities');
} else {
// we're in a course
$this->title = 'Ask a Question'; //get_string('activities');
But it didn't make any difference for me :-(
Hi Daryl,
Getting soooooo close. I echo what Jon says above-- but at least for the first time from within a course it sent email to both admin and teacher, and it took me back to the course--yeah.
I also want to add a couple of things.
1. I am not sure an admin would really even want to get a copy of the email from within a course . Also, there is no way for the admin to tell where that email came from (what course or the site homepage) unless a subject line is pre-filled.
2. This is pickily wickily--will you please capitalize the "page titles" (contact form, thank you) so that they are consistent with the rest of the nav bar.
Thanks
Chardelle
Dan,
Just tried the code change and its good. Now the block has a different name when in a course.
Now, would you know what code I could add that would send the email only to the teacher when the block is in a course and not to the admin.
WP,
That might work, but I just don't see why an admin would want to get a bunch of emails from students asking the teacher questions about a course.
Thanks,
Chardelle
I have posted the changes noted below to cvs. Mind you that there is about a 5 hour sync period before the changes are public.
Jon said: 1. Regardless of whether someone is logged in or not, or whether they have chosen to keep their email address private, the "From" address used by the Contact Form is the default noreply address set in the Config->Variables page. It would be helpful if this could be set to show the email address of the sender.
[EDITED:] Actually this is expected behavior. The headers of the email should be from the site admin. The email of the user who is sending the message is listed in the body of the email, not in the header.
Jon said: 2. When the form is submitted, the "Continue" link points to http://domain/course/view.php?id=1 - which forces the log in page in you're not logged in. It would be helpful if this could just return to the site main page (or even better would be a configurable 'return to' page).
I have changed the continue link to take you back to the course only if the courseid is valid (not 1 - 1 means site) and back to the site otherwise.
Jon said: 3. The code in block_contact_form.php suggests that the name of the block is different depending on whether the block is on the front page or within a course...
Fixed as Dan noted.
Chardelle said: 1. I am not sure an admin would really even want to get a copy of the email from within a course . Also, there is no way for the admin to tell where that email came from (what course or the site homepage) unless a subject line is pre-filled.
I added a new config option to allow the admin to select whether or not to receive emails from within courses.
To get to the admin configuration for this block visit yoursite.edu/moodle/admin then click blocks and click the settings link for the "Ask a question" block.
Chardelle said: 2. This is pickily wickily--will you please capitalize the "page titles" (contact form, thank you) so that they are consistent with the rest of the nav bar.
Done.
WP1 said:Maybe a hidden subject field could be place in the code which is coded to say somthing like,
Contact Mail from Course BlaBlaBla.
Good idea. The subject line is now prefaced by the course short name in square brackets.ie "[EN101] Can I take that quiz again?"
Hi Hansen,
I tried to install the block.
I got an error.
Warning: file(c:\program files\easyphp1-7\www\moodle/blocks/__MACOSX/block___MACOSX.php): failed to open stream: No such file or directory in c:\program files\easyphp1-7\www\moodle\lib\blocklib.php on line 21
Can you help me resolve this.
I must have gone wrong somewhere,
Garry
Hi Daryl,
Can you help a little. I am stuck
There are many post and getting to the last Zip File is difficult.
Can you advise where the latest zip is. A fresh upload will be welcome by all.
I am having porblems the link to my post is Re: Contact form block (version 5)
Look forward for your help.
The block looks excitng and I look forward to using the same.
Garry
First open yoursite.edu/moodle/admin then click blocks and click the settings link for the "Ask a question" block.
Now change the option of sending email to admins and teachers to just sending emails to teachers.
Please let us know if that is now working for you so that we can find the problem.
Hi Daryl,
I hate to do this but.......
The continue link when not logged in, is still taking me to the login page rather than back to the site index. Maybe because course/view.php is in the link Moodle thinks you need to login?
} else {
$continuepage = $CFG->wwwroot . '/course/view.php?&id='. $fromcourse;
Also, about line 10 in form.php, "contact form" didn't get capitalized.
Other than that everything works fine.
(And as to the above post--I think the option to send emails only to teachers is the default--so it should be working -- make sure you are using version 1.2 of the contact form)
The fix is now in cvs. Thank you for catching it.
The continue link when not logged in, is still taking me to the login page rather than back to the site index
It is definitely because course/view.php enforces login. IMHO it should not force login if the course being viewed is the site page. Since it does I added code to try to redirect to $CFG->wwwroot if there was no course specified.
Perhaps your site course id is not 1.
What is the URL that the continue link points to when a guest in an anonymous accessible course sends a message?
Hi Daryl,
I really don't know anything about site id. Where do I find it? But the link is going to:
http://mymoodletestsite.com/blocks/contact_form/thanks.php?fromcourse=1
Hi n,
The sf.net site status page says this:
"( 2004-09-17 10:27:57 - Project CVS Service ) As of 2004-09-17 there is a problem with the CVS host serving anonymous CVS, nightly tarballs and ViewCVS for projects that start with the letters m, n, p, q, t, y and z. We currently do not have an estimate on when they will be back up. "
We'll probably just have to be patient and wait for it to be fixed.
the contact form.zip file isn't listed, any idea why?
Probably because no blocks are listed there - we're all waiting for the promised block repository.
I just installed it but there is the infamous sesskey problem when I try to change the settings to use a link instead of a button for the "contact me". However, it actually works apart from that - emails are successfully sent.
Tim.
This has actually proven to be a pretty useful little block for us. We have two versions: contact_admin_support (for issues relating to logins, enrollment keys, etc.) and contact_tech_support (for specific website related issues). We had to tweak the tech_support block just a little bit because we don't have an actual tech_support user account, just an e-mail address for our webmaster.
Thanks!
I am a bit confused.
Where can I find the last release of the contact_form?
What does it contain?
I found in cvs:/contrib/
block_contact_form.php
config.html
form.php
readme.txt
thanks.php
db/mysql.php
db/postgres7.php
db/mysql.sql
db/postgres7.sql
and somewhere else I found the same list of files with the following addendum too
config_global.html
config_instance.html
form.html
Then I have a problem: I move the contact_form folder into the /moodle/block folder and I go to the administrator page of Moodle but nothing happens and the block doesn't appear in a corse addBlock dropDown menu.
Can anybody explain me where I fail?
Thank you in advance.
Sorry for the too elementary question.
I too was trying to add this from cvs and have failed - nothing happens when I go to mysite/admin - (this is probably me because I haven't used cvs like this before), but nevertheless.....
I assumed that the correct files were in block_contact_form_1.5 not contact_form (in which the files are currently 17 months old, whereas the others are 7 months old). Is this right?
cheers
Mandy