Giter Club home page Giter Club logo

michael-milette / moodle-local_contact Goto Github PK

View Code? Open in Web Editor NEW
21.0 6.0 13.0 310 KB

Contact Form is a Moodle plugin that allows your site to process information submitted through HTML forms to the site's support email address. For premium support, contact us at https://www.tngconsulting.ca/contact

Home Page: https://moodle.org/plugins/local_contact

License: GNU General Public License v3.0

PHP 100.00%
moodle moodle-plugin moodle-local hacktoberfest

moodle-local_contact's Introduction

Local Contact Form plugin for Moodle

PHP Moodle GitHub Issues Contributions welcome License

Table of Contents

Basic Overview

The Contact Form plugin for Moodle processes information submitted through a web form, sending it by email.

Examples uses for this plugin include:

  • Contact us form;
  • Support request form;
  • Request a course form;
  • Information request form;
  • Lead generation form;
  • Membership application form.
  • Quiz question issue report form.

Several pre-configured templates are available when used with the FilterCodes plugin. They include:

  • {formquickquestion}
  • {formcontactus}
  • {formcourserequest}
  • {formsupport}
  • {formcheckin}

See The Quick and Easy method for details.

(Back to top)

Requirements

This plugin requires Moodle 3.0+ from https://moodle.org .

It may work with previous versions of Moodle all the way back to Moodle 2.7 but it has not been tested yet. If it works for you, let us know. Tip: You might need to modify the version.php in order for Moodle to let you install it on earlier versions.

(Back to top)

Download Contact for Moodle

The most recent STABLE release of Contact Form for Moodle is available from: https://moodle.org/plugins/local_contact

The most recent DEVELOPMENT release can be found at: https://github.com/michael-milette/moodle-local_contact

(Back to top)

Installation

Install the plugin, like any other plugin, to the following folder:

/local/contact

See https://docs.moodle.org/en/Installing_plugins for details on installing Moodle plugins.

(Back to top)

Usage

Before getting started:

  • Ensure email settings are properly configured in Moodle.
  • Ensure that you have configured the support name and email address in Moodle.

Creating a new form

The Quick and Easy method

By far, The quickest way to get started is to use the FilterCodes Moodle plugin. As of version 1.3.0, it includes several plain text tags that you can easily copy and paste into any Atto editor. The {tags} include:

  • {formquickquestion} : Adds a "quick question" form to your course. Form only includes a Subject and Message field. Note: User must be logged in or the form will not be displayed.
  • {formcontactus} : Adds a "Contact Us" form to your site (example: in a page). Form includes Name, Email address, Subject and Message fields.
  • {formcourserequest} : Adds a "Course Request" form to your site (example: in a page). Unlike Moodle's request-a-course feature where you can request to create your own course, this tag allows users to request that a course they are interested in be created. Could also be used to request to take a course. Form includes Name, Email address, Course name, Course Description.
  • {formsupport} : Adds a "Support Request" form to your site (example: in a page). Form includes Name, Email address, pre-determined Subject, specific Subject, URL and Message fields.
  • {formcheckin} : Adds a "I'm here!" button to your to your course. Form does not include any other fields. Note: User must be logged in or the button will not be displayed.

Custom method

This plugin is for administrators with a little knowledge of HTML forms. You can simply copy and paste any of the examples from the Wiki to get started.

To create a new web form on your site, start by adding a Moodle page or HTML block. Be sure to switch to the Source Code view button in the Moodle Atto WYSIWYG editor before entering or pasting HTML code similar to the following:

<form action="../../local/contact/index.php" method="post" class="contact-us">
    <fieldset>
        <label for="name" id="namelabel">Your name <strong class="required">(required)</strong></label><br>
        <input id="name" name="name" type="text" size="57" maxlength="45" pattern="[A-zÀ-ž]([A-zÀ-ž\s]){2,}"
                title="Minimum 3 letters/spaces." required="required" value=""><br>
        <label for="email" id="emaillabel">Email address <strong class="required">(required)</strong></label><br>
        <input id="email" name="email" type="email" size="57" maxlength="60" required="required" value=""><br>
        <label for="subject" id="subjectlabel">Subject <strong class="required">(required)</strong></label><br>
        <input id="subject" name="subject" type="text" size="57" maxlength="80" minlength="5"
                title="Minimum 5 characters." required="required"><br>
        <label for="message" id="messagelabel">Message <strong class="required">(required)</strong></label><br>
        <textarea id="message" name="message" rows="5" cols="58" minlength="5"
                title="Minimum 5 characters." required="required"></textarea><br>
        <input type="hidden" id="sesskey" name="sesskey" value="">
        <script>document.getElementById('sesskey').value = M.cfg.sesskey;</script>
    </fieldset>
    <div>
        <input type="submit" name="submit" id="submit" value="Send">
    </div>
</form>

That is it. Just save and you are done.

Note: If you are putting the form into a block, you will need to adjust the "../.." part in the action of the form so that it is relative to the webroot of your Moodle website. If you are using the FilterCodes plugin, you can simply use {wwwroot} and it will work anywhere you put the form whether it is in a page or a block.

Example:

<form action="{wwwroot}/local/contact/index.php" method="post" class="contact-us">
:       :       :       :       :

To see a full example of the above form, see Contact Us with FilterCodes example.

Customizing the form

You can customize your form to suit your particular requirements. You will need to be familiar with how to create basic HTML5 web forms. If you are not, take a look at the HTML5 Forms tutorial.

Almost any type of HTML field included with the form should automatically appear in the email. Example: text, password, textarea, radio, checkbox, select drop-down, hidden and more. See the section on Limitations.

In the previous example, the form's class "contact-us" is not required but is simply included to help you to apply CSS styling to the form. Feel free to change it to anything you like.

REQUIRED FIELDS: The following input fields are required in order to avoid the built-in anti-spam protection. If these input fields are not present in the form, it will not work:

  1. name - You can create an alias for this field name by editing the field-name string in the Moodle language editor. If user is logged in, this field will be ignored and the users full name as registered in Moodle will be used instead. If the user is currently logged in (not guest), this field will be ignored if it exists and user profile info (firstname lastname) will be used instead.
  2. email - You can create an alias for this field name by editing the field-email string in the Moodle language editor. If the user is currently logged in (not guest), this field will be ignored if it exists and user profile info (firstname lastname) will be used instead.
  3. sesskey - Must include both the hidden sesskey field as well as the SCRIPT line below it.
  4. submit - The name of the button.

Your FORM tag must have an action set to ../../local/contact/index.php and a method set to post.

OPTIONAL FIELDS: Although not required, the following fields have special meaning to Contact Form:

  • subject : If you want the subject of the email to contain content from the submitted web form, your form must include a field called subject. You can create an alias for this field name by editing the field-subject string in the Moodle language editor.
  • message : If you want a textarea field, like a Message field, to be formatted properly when inserted in the email, the field must be called message. You can create an alias for this field name by editing the field-message string in the Moodle language editor.
  • recipient: Add this field if you want to specify a recipient other than the Moodle support email address. This field must contain an alias, not an email address. See the section on Configuring the List of Recipients in this documentation.

You can also add the referring URL, the page that the user was on before going to the form, by adding the following to your form:

<input type="hidden" id="referrer" name="referrer" value="">
<script>document.getElementById('referrer').value = document.referrer;</script>

An side benefit to including these two lines is that the Continue button, which appears after you submit the form, will take the user back to the form's referrer URL instead the site's front page.

If you would rather have the Continue button take the user back to the form itself, simply replace document.referrer with document.location.href. So the above two lines would become:

<input type="hidden" id="referrer" name="referrer" value="">
<script>document.getElementById('referrer').value = document.location.href;</script>

This will result in the form's address being inserted into the email in the referrer field

If you prefer to have the continue button always take the user to a different page, you can specify the URL in the input field. Just be sure that the page is on the Moodle site. The continue button will not allow you to take the user to a different website. Example:

<input type="hidden" id="referrer" name="referrer" value="https://moodle.example.com/mod/page/view.php?id=21">

Note that, in these two last examples, the referrer field will no longer actually refer to the page from where the user actually came from before the form which can be a little misleading. For a support page, it is recommended to use document.referrer with the script tag in order to submit the URL of the page from where they came. This will be helpful when the student submits something like "Lesson 2 of the course didn't work" but offers no clue which course they were in at the time.

Returning the student back to the page they were on before the form was submitted is also helpful if it would be rather complicated to navigate back to where they were before they submitted the form. This is especially important if you are dealing with students who may have accessibility issues.

Additional tips

If you want to insert spaces in your field names, use underscores "_" in your form field id and name. Contact Form for Moodle will replace these with a space before inserting the field name into the email message.

Field id/name tokens must begin with a letter. They may optionally also contain any combination of letters (a-z), numbers (0-9), underscores, dashes, periods and colons (_-.:). They are not case sensitive.

Configuring the email message

To edit the language strings including the email message to be sent to the user, you will need to make the changes using the Moodle language editor. To do this:

  1. Login to Moodle as an Administrator
  2. Navigate to Home > Site Administration > Language > Language Customization.
  3. Select the language you wish to modify and then click Open Language Pack for Editing button.
  4. Select the local_contact.php from the list and click the Show Strings button.

For more information on using the language editor, see the Moodle documentation on Language Customization.

The message can include the following tags which will be substituted at the time the message is sent:

  • [fromemail] : User's email address as entered in the web form or the users registered email address if logged in.
  • [fromname] : User's name as entered in the web form or the users registered first and last name if logged in.
  • [http_referer] : URL of the web form page that the email was generated from.
  • [http_user_agent]: Web browser.
  • [lang] : Language that the user was viewing the website in at the time they submitted the form.
  • [sitefullname] : Site's fullname.
  • [siteshortname] : Site's short name.
  • [siteurl] : URL of the website.
  • [supportemail] : Site's support email address.
  • [supportname] : Site's support name.
  • [userip] : Best attempt to determine the user's IP address. Will be the firewall address if they are behind one.
  • [userstatus] : Displays the user's current status if they are known to the Moodle site, either because they are logged in or by their email address.

Note that, in the future, the email message will be configurable from within the plugin's settings.

Optional Contact Form for Moodle settings

Contact Form for Moodle includes the following settings. These are available on the plugin's Settings page by going to:

Site administration > Plugins > Local plugins > Contact Form

Override the sender's (FROM) email address

You can optionally specify an emails address from which emails will be sent. If this field is blank, by default emails will be delivered from the no-reply email address.

Configuring the List of Recipients

By default, messages sent from the Contact Form for Moodle will be delivered to your Moodle support contact email address. However, you can optionally specify a different recipient on a per form basis. Configuring this requires two additional easy steps:

Step 1 - Create the List of Available Recipients

Start by specifying a List of Available Recipients in the plugin's settings.

The format for each recipient is alias|emailaddress|name. You should only enter one recipient per line. Incorrectly entered lines and blank lines will be ignored.

For example:

tech support|[email protected]|Joe Fixit
webmaster|[email protected]|Mr. Moodle
electrical|[email protected]|Nikola
history|[email protected]|Mr. Darwin
law|[email protected]|Isaac Newton
math|[email protected]|Galileo
english|[email protected]|Mark Twain
physics|[email protected]|Albert
science|[email protected]|Mr. Edison
philosophy|[email protected]|Aristotle

Note that this list is not automatically populated in forms. You will need to do that manually in the next step.

Step 2 - Add a field to your form.

Single Recipient - This can be done by specifying the recipient's alias in a "hidden" type input field in your form. For example:

<input type="hidden" name="recipient" id="recipient" value="webmaster">

One of Many Recipients - You can also create a drop-down (select) list in your form and have the user specify the recipient. For example:

<select name="recipient" id="recipient" required>
    <option value="">Please select...</option>
    <option value="tech support">Technical support</option>
    <option value="webmaster">Moodle administrator</option>
</select>

A different form on the same site might have:

<select name="recipient" id="recipient" required>
    <option value="">Please select...</option>
    <option value="history">History teacher</option>
    <option value="math">Math teacher</option>
    <option value="english">English teacher</option>
    <option value="philosophy">Philosophy teacher</option>
</select>

Notice that you can include any number of recipients in your form's drop-down list. You need not include all of them. If a specified alias is not in the List of Available Recipients, the email message will default to being delivered to the Moodle site's support email address.

Select multiple items

If you are using a select form where you allow multiple items to be selected, all of the selected items will be merged together in a commas/space delimited list. Example:

<select multiple name="cars[]" id="cars">
    <option value="">Please select...</option>
    <option value="TOYOTA">Toyota</option>
    <option value="GM">General Motors</option>
    <option value="VOLKSWAGEN">Volkswagen</option>
    <option value="NISSAN">Nissan</option>
    <option value="HYUNDAI">Hyundai</option>
    <option value="FORD">Ford</option>
    <option value="CHRYSLER">Chrysler</option>
    <option value="HONDA">Honda</option>
    <option value="BMW">BMW</option>
</select>

Important: Don't forget to end the name of your field with [] or all you will see is the last selected item.

Configuring reCAPTCHAs

Note: If Moodle's reCAPTCHA is not configured, you will not see this setting.

To use reCAPTCHA in your Contact form, you must:

  • Configure Moodle's reCAPTCHA settings. See Site administration > Plugins > Authentication > Manage authentication. These settings are near the bottom of the page.
  • Install and enable the filter_filtercodes plugin.
  • Add the {recaptcha} tag inside your form, usually right before the Send button. This will be converted into HTML code when your form is displayed. For more information on inserting a {recaptha} tag, see the FilterCodes documentation.

However, even if reCAPTCHA is enabled, you can tell Contact Form for Moodle not to use it. Just go into the settings for Contact Form, check the box for No reCAPTCHA and save. In this case, you will not need to include the {recaptcha} tag in the form. Example:

<form action="../../local/contact/index.php" method="post" class="template-form">
    <fieldset>
        <label for="name" id="namelabel">Your name <strong class="required">(required)</strong></label><br>
        <input id="name" name="name" type="text" pattern="[A-zÀ-ž]([A-zÀ-ž\s]){2,}" title="Minimum 3 letters/spaces." required="required" value="" style="width:100%;"><br>
        <label for="email" id="emaillabel">Email address <strong class="required">(required)</strong></label><br>
        <input id="email" name="email" type="email" required="required" value="" style="width:100%;"><br>
        <input type="hidden" id="sesskey" name="sesskey" value="">
        <script>document.getElementById('sesskey').value = M.cfg.sesskey;</script>
        **{recaptcha}**
    </fieldset>
    <div>
        <input type="submit" name="submit" id="submit" value="Send">
    </div>
</form>

Adding support for attachments

In order to add support for one attachment to your form, you must:

  1. Enable attachments in the Contact Form plugin settings. Otherwise attachments will be ignored, even if you have a field for it in your form. If you try to submit an attachment but get the message File attachments not enabled., you did not enable this feature.
  2. Add enctype="multipart/form-data" to the tag.
  3. Add the following two tags in the form. You can change the word Attachment a file but everything else must remain as is.
<label for="attachment" id="attachmentlabel">Attachment a file</label><br>
<input type="file" id="attachment" name="attachment">

Here is a complete example of the previous Contact Us form example but with these changes:

Your name (required)

Email address (required)

Subject (required)

Message (required)
<textarea id="message" name="message" rows="5" cols="58" minlength="5" title="Minimum 5 characters." required="required"></textarea>
Attachment a file:
<script>document.getElementById('sesskey').value = M.cfg.sesskey;</script>

Require login

The Require login setting requires that users be logged-in in order to be able to submit the form. If a form is submitted and the user is not logged-in they will be redirected to the login page. If you require users to be logged-in, it is also highly recommended that you also place your form on a page which is only accessible to logged-in users. Guest users are not considered to be logged-in.

(Back to top)

Updating

There are no special considerations required for updating the plugin.

The first public BETA version was released on 2016-12-05. For more information on releases since then, see CHANGELOG.md.

(Back to top)

Uninstallation

Uninstalling the plugin by going into the following:

Home > Administration > Site Administration > Plugins > Manage plugins > Contact Form

...and click Uninstall. You may also need to manually delete the following folder:

/local/contact

(Back to top)

Limitations

This is not a form builder.

The plugin doesn't currently properly support more than one textarea type fields. Additional textareas will still work however they won't be formatted as nice.

Any HTML entered will be escaped. You cannot use any kind of HTML formatting or markup/markdown other than pressing ENTER at the end of a paragraph.

You cannot configure the Contact Form email processor on a per form basis. All contact forms on your site will share:

  • The message that is displayed to the user after the message has been sent.
  • The footer of the email containing additional user information.
  • Enabling/disabling of the autoresponder.
  • The autoresponder message (if enabled).

Web forms are limited to 1024 fields including hidden fields and the submit button. Total size of the submission may not exceed 256 KB.

(Back to top)

Language Support

This plugin includes support for the English language. Additional languages including French are supported if you've installed one or more additional Moodle language packs.

Some core fields will be different if a language pack is available for your language. On a French Moodle site, for example (fielname on English site => fieldname on French site):

  • email => courriel
  • message => message
  • name => nom
  • subject => objet

So on a French site, you would need to use the French versions of the field names or Contact Form will not recognize them. For more information, see the section called Customizing the form.

Pro tip: Creating a multi-language Moodle site? Use the FilterCodes {getstring} tag to populate the correct field name. Example:

Note: If no language pack is available for your language, the plugin will default to the English language pack. However, if you need a language that is not yet supported, please contribute translations using the Moodle AMOS Translation Toolkit for Moodle at:

https://lang.moodle.org/

This plugin has not been tested for right-to-left (RTL) language support. If you want to use this plugin with a RTL language and it doesn't work as-is, feel free to prepare a pull request and submit it to the project page at:

https://github.com/michael-milette/moodle-local_contact

(Back to top)

FAQ

Answers to frequently asked questions

How do I make this form available to everyone, even if they are not logged in?

Assuming you have not enabled "Force users to log in" in Moodle settings, the easiest way is to add a page or block to your Moodle Frontpage (also known as Home page).

  1. Login as a Moodle administrator.
  2. Go to your Front Page.
  3. Turn editing on.
  4. Add a Page type activity/resource.
  5. Insert your HTML form or related FilterCode (if you are using it) into the content field and save. If pasting HTML code, make sure that the WYSIWYG editor is in HTML mode.

Since you don't need to be logged into your Moodle Frontpage to see it, your form will also be accessible to visitors to your site who are logged-out, logged-in as a guest as well as to regular logged-in users. If this option is not available to you, the process is a little more complicated as it involves making a course available to guests and having Moodle automatically logged them in as guests.

Why isn't my form working?

The quick and easy way to create webforms in Moodle is to simply install FilterCodes and use its tags. Be sure to set the filter to On in Moodle's Manage Filter settings and set it to filter Content and headings. Built-in forms include {formquickquestion}, {formcontactus}, {formcourserequest}, {formsupport}, {formcheckin}. More information for FilterCodes method.

If you are not using FilterCodes, be sure to replace any reference to tags that look like {tagname} that might be found in your HTML form. More informaiton on HTML method. For example, if your form contains {wwwroot} and the webroot your Moodle site is https://example.com, then replace {wwwroot}/local/contact/ with https://example.com/local/contact/ . Look through your form as there may be others depending on the sample code upon which you based your form.

Anytime your form doesn't work, be sure to try it in a Moodle page or block using the Boost theme with the current language set to English. If it works there, chances are that it is the theme or plugin you are using that is causing the issue, not FilterCodes or Contact for Moodle. As with the Static Pages plugin (see below), you may find that there is a setting that needs to be changed. If not, contact the author/maintainer of the plugin and ask them to add support for filtering in their theme or plugin.

If the form works in English and not in your preferred language, you may need to translate the names of some of your fields. This is required if you want the field names to appear in your language in the email. More information on Language support

Sesskey error

If you are getting an error that mentions sesskey, you may have forgot to include the JavaScript snippet in your form:

<input type="hidden" id="sesskey" name="sesskey" value="">
<script>document.getElementById('sesskey').value = M.cfg.sesskey;</script>

If you have FilterCodes installed, you can simply replace all of the above code in your form with:

{formsesskey}

If JavaScript does not work in your form, you can replace the above code with the following HTML. Be aware that it will override one of several anti-spam protections built into Contact Form (requires FilterCodes):

<input type="hidden" id="sesskey" name="sesskey" value="{sesskey}">

Static Pages plugin compatibility

The recommended way of using Contact for Moodle is to create your webmail form in a page or block. However, there may be use cases where you might prefer to use the local_staticpage plugin. In order for this to work, you will need to configure a couple of its settings:

  • Enable the Static Pages plugin's Process Filters (processfilters) setting to enable processing of FilterCodes.
  • Disable its Clean HTML code (cleanhtml) setting to prevent StaticPage from deleting or filtering out some of the required HTML code in your form.

This demonstrates how to use FilterCode Contact Form templates with the Static Pages to create a quick Contact Us form. Start by copying the following code into a text file called contact.html and saving it:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Contact Us</title>
</head>
<body>
    <h1>Contact Us</h1>
    {formcontactus}
</body>
</html>

Next, simply upload the contact.html file into Static Pages in order to make it available on your Moodle site.

All I see is the word "Forbidden" or a blank screen after submitting a form. What should I do?

This plugin has been extensively tested. If you are still getting this error, it is likely that you will need to fix your form and/or enable Moodle debugging. Alternatively you can try the form logged in as a Moodle administrator. This will enable the display of additional diagnostic information.

Where do emails go when they are submitted on my Moodle website?

Emails are sent to the Support Email address. Logged in as a Moodle administrator, you can find out the email address by going to:

Administration > Site Administration > Server > Support Contact

If the field is empty, take note of the indicated default email address.

Why are emails submitted on my Moodle website not being delivered?

Make sure Moodle email is working. We recommend test your Moodle email system using the eMailTest plugin:

https://moodle.org/plugins/local_mailtest

My site successfully completed the eMailTest process. Why is it still not working?

If you still can't get your web form to work, the problem might be your form. Try using HTML sample form included in the Usage section. Then customize it to meet your needs.

I am still getting a lot of spam emails through my web form. Can I block certain IP addresses?

There are a couple of ways you can blacklist an IP address. The best way is to add them to your web server settings. Consult your web server documentation for more information. If you don't have access to those settings, Moodle Administrators can add the IP addresses to the Moodle IP Blocker settings. For more information, see:

https://docs.moodle.org/en/IP_blocker

Why does the User's IP address ([userip]) says "::1" or 0:0:0:0:0:1 instead showing a real IP address when I receive an email submitted from the form?

::1 and 0:0:0:0:0:1 are the equivalent of 127.0.0.1 (localhost). This should only happen if your web browser is on the same computer as the web server. Otherwise you should be seeing a real IP address.

Can I include my favourite captcha in a form?

No. Only Moodle's reCAPTCHA will work. See the Usage section for more information.

Moodle's reCAPTCHA is enabled. Do I need to use it in my Contact forms?

It is not required. However, if you don't want to use it, you must check the No ReCAPTCHA checkbox in the plugin's settings.

Can I add a check box that must be checked, like for accepting the privacy policy, before the user can submit the form?

Absolutely. Information on how to do this will be coming in the future. (Hint: It requires a JavaScript code snippet)

I have a multilingual Moodle site. Why does the form works in one language but not in the other?

Each language file defines the names of the fields for your form. To make a form work for all languages, change the name of this fields for each language by editing the "field-" strings in the Moodle language editor so that they are all the same ones you used in your form).

How can I change the names of the fields that appear in the email?

In your form, change the value of "label for=" to the word you want. On the next line, change the id= and the name= to be the same as the one for the "label for=". Finally, if the field was "name", "email", "subject" or "message", you will also need to edit the related "field-*" string in the Moodle language editor.

What types of web forms should not be implemented using Contact Form?

This plugin is not suitable for any form whose data should not end up in an email inbox. For example, Moodle natively supports several excellent types of forms processors such as Feedback, Survey and Database. Unless your e-commerce solution involves low volume semi-manual process, this could be better handled by applications designed with this in mind. Signing up for mailing list subscriptions should be done through a service such as Aweber, Constant Contact, MailChimp and other similar services.

Note: The mention of any 3rd party product other than Moodle and FilterCodes is not meant as an endorsement or recommendation. They are simply provided as examples.

How can I make the form only available to logged-in users?

To only display your form for logged-in users, ensure that it is on a Moodle page that is only viewable by logged-in users. User access to pages and blocks is controlled by Moodle, not by this plugin. With that in mind, if you don't include a name and email address field in your form, only registered users who are logged-in to the Moodle site will be able to submit the form. Another option is to use the {if...}{/if...} conditional tags in the FilterCodes plugin to control who can see the form.

Why is the name and/or email address I entered in a form getting changed when submitted?

This only happens if a user is logged in. In this case, their registered first and last name and email address will be used instead of the name and email address entered in a form.

Can I include user profile fields and custom profile fields in the email footer and confirmation email message?

Yes. Not all profile fields are available, but you can do it by inserting FilterCodes tags.

Why does the "Continue" button always take me back to the front page instead of back to the referrer URL?

This may happen in a few situations:

  1. If you manually specified a referrer URL in the form instead of using the recommended JavaScript snippet, this can work but the referrer URL must be fully qualified, be from the Moodle site and begin with the address of your front page ($CFG->wwwroot).
  2. If you try to trick it by manually specifying a URL from a different website, that URL will be ignored and your user will be redirected to the front page.
  3. If you access the from by manually typing in it's URL or using a bookmark, the continue button will still take you back to the front page since this would result in no referrer URL being available.

Why do the form fields disappear every time I save my form in Moodle?

ANSWER 1: This will happen if you are using the old TinyMCE editor in Moodle instead of the newer Atto editor. With default settings, the TinyMCE editor would filter out HTML form tags when you went to save it.

The easy solution is to simply switch your preferred editor to the Atto editor, edit and then save your form. The form fields should remain intact. Once you save your form using the Atto editor, you can switch your preferred editor back to TinyMCE and the form will continue to work for everyone. However, if one day you or someone else should you forget and edit the form with the TinyMCE editor, the fields will disappear again.

If, for whatever reason, you really want to use the TinyMCE editor, you can still get it to work but you will need to modify its Moodle Configuration Settings to allow HTML form field tags.

Additional information:

ANSWER 2: If you are having problems specifically with the StaticPages plugin, go into its configuration options and set the Clean HTML code to "No, don't clean HTML code". Otherwise the plugin will filter out HTML tags including all your form tags. (thanks to Alex Ferrer for this solution)

Can I add a form to the Moodle login page?

It is definitely possible. Here is what you need to do:

  1. Go to Site administration > Plugins > Authentication > Manage authentication.
  2. Scroll down to the Instructions field.
  3. Insert your form in this field.
  4. Click Save Changes at the bottom of the page.

That's it! Your form will now appear in the section of the page called "Is this your first time here?" on the Moodle login page.

With that said, if what you really want is to have the ability to approve any registration requests on your site, you might be interested in taking a look at the "Email-based self-registration with admin confirmation" plugin. New users complete would then complete the self-registration process. However, before they can gain access to the site, a Moodle Administrator will receive an email and need to approve. You can find the plugin by going to https://moodle.org/plugins/auth_emailadmin

Are there any security considerations?

There are no known security considerations at this time.

Other questions

Got a burning question that is not covered here? Checkout the troubleshooting section of our Wiki. If you still can't find your answer, submit your question in the Moodle forums or open a new issue on GitHub at:

https://github.com/michael-milette/moodle-local_contact/issues

(Back to top)

Contributing

If you are interested in helping, please take a look at our contributing guidelines for details on our code of conduct and the process for submitting pull requests to us.

Contributors

Michael Milette - Author and Lead Developer

Big thank you to the following contributors. (Please let me know if I forgot to include you in the list):

  • geoffreyvanwyk: Fixed links in the documenation (2023).
  • alexmorrisnz: Add support for an attachment (2023).
  • HirotoKagotani: Use the system-wide setting for fullname display (2021).
  • kmoouni: Option to restrict usage of the plugin to logged in users (2017).

Thank you also to all the people who have requested features, tested and reported bugs.

Pending Features

Some of the features we are considering for future releases include:

  • Add ability to specify custom profile fields in the body of the email message.
  • Option to enable the auto-responder / confirmation message.
  • Auto-responder will be editable in the plugin's settings.
  • Add additional examples of web forms to the documentation (see Wiki).
  • Create a basic form builder.
  • Make all submitted web form fields available as markup tags that you can insert into your message template.
  • Add some Moodle logging of sent messages.
  • Add a Whitelist and Blacklist for email addresses.
  • Add a Whitelist and Blacklist for email domains.
  • Add support for form-specific custom autoresponders.
  • Add support for form-specific custom confirmation message.
  • Add support to optionally only use autoresponder feature without also sending the main email message.

If you could use any of these features, or have other needs, consider contributing or hiring us to accelerate development.

(Back to top)

Motivation for this plugin

The initial development for this project was sponsored by the kind folk at l'Action ontarienne contre la violence aux femmes together with TNG Consulting Inc.

(Back to top)

Further information

For further information regarding the local_contact plugin, support or to report a bug, please visit the project page at:

https://github.com/michael-milette/moodle-local_contact

(Back to top)

License

Copyright © 2016-2024 TNG Consulting Inc. - https://www.tngconsulting.ca/

This file is part of the Contact Form plugin for Moodle - https://moodle.org/plugins/local_contact/

Contact Form is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Contact Form is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Contact Form. If not, see https://www.gnu.org/licenses/.

(Back to top)

moodle-local_contact's People

Contributors

alexmorrisnz avatar geoffreyvanwyk avatar hirotokagotani avatar michael-milette avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

moodle-local_contact's Issues

Validation error with multi-select field

Hello, first I want to thank you for your contribution with this fantastic plugin. The problem that I have detected occurs when we have a multiple select element in the form.

In your documentation, it is well reflected that the name of this field must end with [].

But, no matter how many times I tested, I could not get the information of this field to appear in mails.

Reviewing the code, in the function "sendmessage", when it begins to process the collected information, there is a conditional:

if (!in_array($key, array('sesskey', 'submit')) && trim($value) != '') {

The parameter provided to trim should be a string. But when a multi-select field is used in the form then it is an array.

PHP Warning: trim() expects parameter 1 to be string, array given in /sites/yoursite/files/local/contact/classes/local_contact.php on line 268

A solution could be to move this part of the code, before excluding the empty information fields.

// Join array of values. Example: <select multiple>. if (is_array($value)) { $value = join(', ', $value); }

contact us log

hi , is possible to see database log for the contact us page?

confirmation email does not send

When I test the contact form I receive the email but the user does not receive the confirmation email. Can only see the confirmation message in my page. What I have to do that the user receive a confirmation email too?

Can't save form

Hello Michael,

I still can not insert the contact form.

I inserted the sample code into a text block (in html mode). When I try to save in html mode nothing happens (no saving). When I try to save in regular mode I also can not save because the "required fields" are empty. When I insert a value and try to save it says "wrong session key".

I tried with chrome, firefox and ie. It does not work.

What am I doing wrong?

Suggestion for docs about the available recipients list

Hello, at first, thanks for your work! This plugin saved me a lot of time.
I got a suggestion about documentation. It could be specified, more strictly, that the lines of avaiable recipient list must have no whitespace char before and after the | char. I got some email errors:

Can not send email to user without email: -99
    line 5726 of /lib/moodlelib.php: call to debugging()
    line 312 of /local/contact/class/local_contact.php: call to email_to_user()
    line 111 of /local/contact/index.php: call to local_contact->sendmessage()

After 1h debugging the code, i realized that it was caused by a whitespace char inside the line:

tech support| [email protected]| John Doe

So i removed the illegal chars in this way:

tech support|[email protected]|John Doe

and all worked fine.

I hope it will help!

Just want to show a link, not a block, on the front page

I am not sure if this is a feature request. Maybe this can already be done?

On the front page, I do not want to show the entire form, just a link that will take somebody to the form.

I tried saving the sample "contact us" form as a static page, but that does not work. I can link to it, but it will not accept input.

"Forbidden" error

Moodle 3.7.7. Boost theme. Using LetsEncrypt. No SSL or TLS set on SMTP server. I am not using Apache mod_rewrite.

Cannot seem to get past this error. I am pretty sure the /local/contact/index.php file is being found. I have tried changing permissions to 755. I think this has something to do with the sesskey. I used to get a sesskey error, now I just get one word "forbidden."

Users can self register on my Moodle site, so I know the email is working.

Feature request: Add ability to edit the message template

In order to modify the message template which is used when sending a message, you currently need to go into the Moodle language editor. It would be nice if this could be done in a WYSIWYG editor in the plugin settings instead.

Bug: Forms break when field names are altered in AMOS

From Georg Wiesinger on Moodle.org:

Hi Michael,

The German translation in AMOS for the required and optional fields (name, email, subject, message) has been changed so, after submitting the form, the respective parameters are missing! Hence a multilingual usage of this plugin is not possible, the AMOS translations should be unified for the form fields concerned or maybe there is another approach to provide individual label translations...

I edited the language file locally, no issues while using different languages anymore! smile

Anyway, this plugin rocks!

Feature request: Ability to disable reply-to field

Some SMTP servers don't like it when the TO address does not match the reply-to field. It would be helpful in these situations if the REPLY-TO field would either be populated with the same address as the TO field or not be included at all.

Add Option to Send from Users Mail Address

Currently emails are sent from [email protected]

This is an issue for us as we want emails routed directly into a helpdesk system where they are automatically converted into a "call".

This system only accepts valid mail addresses on the University domain and in addition to creating the ticket sends users an email with their ticket details.

What we would like to add is an additional admin setting:

  • Setting Name: send_from_user_address
  • Default Value: False (would continue to send via [email protected] as is the case currently)

When enabled this would send emails from the users mail address as opposed to the default Moodle address.

We can add this feature and submit a pull request if you would be likely to accept it?

Contact form

Hi,
I installed the plugin, but I can't get to the email configuration to add the emails for a drop-down list with the emails for different subjects that i added with the HTML tags in a block. When I try to reconfigure the contact form plugin, my only option is to uninstall it.
How can I fix the emails to contact each individual teacher?
Thanks.
Nestor

Request: Configurable recipient email address

Can I suggest to add an option that directs the emails generated by the created contact forms to someone other than the Moodle admin? It would be great if they were sent to a specific email address, i.e. the correct person in the department, rather than admin (especially as this one would be coming from parents). I can't really set up an office admin to get the Moodle admin mail!!

Thanks for the help

Regards

(from Bobby Demers on Moodle.org)

Email only delivered for Admin users

From Charles Duncan : I have implemented Contact Form in Moodle 3.9. It was easy to install and set up and is working well. The only problem is that emails are only being sent if the person using the form has administrator access to Moodle. For teachers, students, guests and non-logged-in users everything appears to work but the email never arrives. I am at a loss as to where to look and I suspect it may be related to some other setting outside Contact Form. Any suggestions?

Send messages only from logged users

Hi, I like this plugin. Simple and easy. :-)
I have only one problem. In my side, it seems only logged users can send messages.
I tried also with Guest user, I can see the static page with the form, but I cannot submit. After click on "send", I have a blank page with the word "Forbidden".
If log in, all is perfect.
Do I have to change something in my config somewhere?
Thanks

Feature Request: Support for reCAPTCHA v2

From David Heuring on Thu, 29 Mar 2018, 8:13 AM on Moodle.org

I have recently upgraded to Moodle 3.4.2+ because the new recaptchaV2 update is included in that version. The one-tick challenge box appears on the new user sign up page so I know it is working correctly. Looks and works great, by the way! However, the recaptcha version in the Contact Form is still the old V1, which is about to lose Google support at the end of the month. I'm wondering why the Contact Form isn't showing recaptchaV2. Everything is set up correctly but it still shows the text-based recaptchaV1. I've unenabled and then enabled recaptcha in the settings but that didn't make a difference. Is this maybe related to the filtercodes plugin and how that works with recaptcha? Any ideas?

reCAPTCHA alternatives

For some users, it is not possible or desirable to use Google reCAPTCHA. Examples of such users include:

  • users from locations which can't access reCAPTCHA (especially China)
  • users concerned about leaking IP and profile data to Google
  • users who object to training neural networks for a private company
  • sites that are handling sensitive data with high level privacy needs (i.e. no 3rd party data processors).

It would be great to have alternative(s) to reCAPTCHA for the local_contact form. This could be:

  1. a simple honeypot for spambots (a hidden submission field that a spam bot enters but a user does not). The technique is described here and I can attest to it being very effective.
  2. adding a simple problem for the contact sender to solve (an addition or division problem for instance)
  3. using an alternative open source (and self-hosted) CAPTCHA alternative like https://github.com/desirepath41/visualCaptcha

While none of these will defeat a directed attack, they are often very effective against simple bots.

Feature request: automatic filling in user profile details

User Case:

Susan is a user in Moodle. She filles in the contactform in the Moodle course to ask a question to the administation department. When she fills in the form her name and e-mailaddress - as placed in her profile - are filled in automatically.

Option: Susan rather has that the reply goes to her private mailadress then the schools, so she alternates the e-mailadress.

Bug: Invalid $user parameter in get_user_preferences() call

From Anisorf Avecok on May 12, 2020 via https://moodle.org/plugins/local_contact

Hi @michael Milette and all "Contuct Us" contributors.
Thanks for sharing this plugin with the community.

I'm having troubles on using the plugin with not authenticated user, it gives me " Invalid $user parameter in get_user_preferences() call". I've checked the configuration of the plugin and I have set Login required: false.
I use the classical template from README.md section Custom Methods with reCaptha and I have FilterCodes plugin from which I use only {wwwroot}.

What am I missing?

Feature Request: Option to remove site name from subject

Currently there doesnt seem to be a way to remove [Moodle Site Name] from the subject of the email sent. This is prefixed on the server side.

It would be useful to have another option to be able to disable this feature:

Setting Name: prefix_subject_with_site_name
Default Value: true (consistent with current version)

When disabled the site name would be removed.

The reason we would like this so that subject lines become clearer / more distinct for our helpdesk and are routed to the correct team. We will be creating several request forms for different purposes.

If you are agreeable to this feature being added we can do this and submit a pull request.

No ReCAPTCHA option has no effect

Whether I check the box or not, checking it will still require the ReCAPTCHA if it is not submitted.

I expected it to not be required if the box was checked.

Select Multiple only processes last selected option

From Kristin Merritt via Moodle.org:

I am trying to create a multiple value select list using this code (example)

Program of Study *
Volvo Saab Opel Audi

When submitted it only pulls the first of the items I select. Is there something I am missing code wise that would stop all selections to come through? I am sorry to have to ask this, seems like a dumb question that I just can't seem to figure out what I am doing.

Bug: & in site fullname and shortname are not handled correctly

Prerequisites

  • I'm reporting the issue to the correct repository.
  • I am running the latest version of this plugin (if not, please upgrade first).
  • I checked the README.md and Wiki documentation but did not find my answer.
  • I searched to make sure that this issue had not already been reported.
  • I have, or I know someone who has, the ability and willingness to test the fix on a Moodle LMS-based site.
  • I am submitting no more than one bug report per issue ticket (please do not submit multiple bugs in one issue ticket).
  • I understand that support is provided by volunteer(s).

What happened?

If the site name included an &, the email will include &

What do you think should have happened?

The email should just show "&" in the site name.

Steps to reproduce

Put an ampersand in the site shortname and then submit a webmail form.

Screenshots

No response

Moodle version

All

Installed Moodle UI Language packs.

  • English only
  • One or more other languages/regional dialects (specify below)
  • Other

If other language(s), please specify

No response

Workaround

No response

Additional information

No response

System information

Not relevant.

Code of Conduct

Feature Request: Quote User's email

Michael,
Is there any way that when a user submits a form they can be sent a copy to the email that they listed in the form?
Thanks,
Kristin

SessKey not required

Whist testing we noticed it was possible to send emails with no sesskey defined in the submit form.

I am not sure if there has been a change not reflected in the documentation or wehther this is a bug.

We were testing as a logged in user.

Feature request: Make name and eMail address optional for logged-in users

Hi Michael,

I really like this plug-in. I am wondering.

Right now the fields name and email are required.
I know I will get questions regarding this, since users are already logged in.
I am wondering if there is a way to fill these fields automatically with the users profile details.
(maybe in away they can change it if they want).

(from Gemma on Moodle.org)

Feature Request: Continue to previous page (was Redirect)

Hi Michael! I hope you had a wonderful holiday season!
Question:
In the documentation, it states:

You can also add the referring URL, the page that the user was on before going to the form, by adding the following to your form:

<script>document.getElementById('referrer').value = document.referrer;</script>

I am not getting the result. Is there something I am doing wrong?

Bug: PHP 8.1 - trim(): Passing null to parameter #1 ($string) of type string is deprecated

Prerequisites

  • I'm reporting the issue to the correct repository.
  • I am running the latest version of this plugin (if not, please upgrade first).
  • I checked the README.md and Wiki documentation but did not find my answer.
  • I searched to make sure that this issue had not already been reported.
  • I have, or I know someone who has, the ability and willingness to test the fix on a Moodle LMS-based site.
  • I am submitting no more than one bug report per issue ticket (please do not submit multiple bugs in one issue ticket).
  • I understand that support is provided by volunteer(s).

What happened?

I get the following message when I submit a form:

Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in local/contact/index.php on line 74

What do you think should have happened?

No errors, notices, or warnings.

Steps to reproduce

  1. Login as any user
  2. Go to the page containing your form.
  3. Fill out the form and submit.
  4. The confirmation message indicates that the message was successfully sent but the deprecation notice also appears when debugging is set to DEVELOPER MODE.

Screenshots

No response

Moodle version

Moodle 4.2

Installed Moodle UI Language packs.

  • English only
  • One or more other languages/regional dialects (specify below)
  • Other

If other language(s), please specify

No response

Workaround

No response

Additional information

No response

System information

PHP 8.1

Code of Conduct

Feature Request: Save Form Responses in database

Prerequisites

  • I am requesting the new feature to the correct repository.
  • I checked the latest version on GitHub and the README.md documentation to ensure that this functionality does not already exist.
  • I searched to make sure that this feature has not already been requested.
  • I have, or I know someone who has, the ability and willingness to test the new feature on a Moodle LMS-based site.
  • I agree to submit one feature request per issue ticket (do not submit multiple requests in one issue ticket).
  • I understand that development and support is provided by volunteer(s) and that all final implementation decisions are up TNG Consulting Inc.

Feature Request - The User Story

For Example, I'm using the Contact form for Lead Generation for the 'Admission Inquiry Form'
I think the responses should be saved in the database along with the Email.

Like Moodle mod_feedback plugin,
we can have responses tab, analysis tab, chart/graphs tab to have a visualisation of the data

Screenshots / Mock-ups

No response

Alterative you have considered

No response

Additional information

No response

Planning on submitting a solution in a pull request (PR)?

Yes

Code of Conduct

Add Setting to Require Login

We are in the proces of adding the following feature and will submit a pull request shortly:

For use the fact non authenticated users can post requests to this plugin is an issue. We only want to use it internally and do not want the form accessible to non authenticated users, this is to be sure it cannot be abused.

  1. Add a checkbox setting to the admin pages "strict_users"
  2. If enabled the login form will not process any emails from guest users instead re-directing them to the login page
  3. This setting will be enabled by default, but that could easily be altered to being disabled by default

Although our HTML forms all require login this would prevent anyone who knew the URL of the local plugin from creating their own POST form and submitting from outside of Moodle when not logged in.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.