Download the PHP package craftcms/contact-form without Composer

On this page you can find all versions of the php package craftcms/contact-form. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package contact-form

Contact Form for Craft CMS

This plugin allows you to add an email contact form to your website.

Requirements

This plugin requires Craft CMS 4.0.0+ or 5.0.0+.

Installation

You can install this plugin from the Plugin Store or with Composer.

From the Plugin Store

Go to the Plugin Store in your project’s Control Panel and search for “Contact Form”. Then click on the “Install” button in its modal window.

With Composer

Open your terminal and run the following commands:

Usage

Your contact form template can look something like this:

The only required fields are fromEmail and message. Everything else is optional.

Redirecting after submit

If you have a redirect hidden input, the user will get redirected to it upon successfully sending the email. The following variables can be used within the URL/path you set:

For example, if you wanted to redirect to a contact/thanks page and pass the sender’s name to it, you could set the input like this:

On your contact/thanks.html template, you can access that from parameter using craft.app.request.getQueryParam():

Note that if you don’t include a redirect input, the current page will get reloaded.

Displaying flash messages

When a contact form is submitted, the plugin will set a notice (Craft 4) or success (Craft 5+) flash message on the user session. You can display it in your template like this:

Adding additional fields

You can add additional fields to your form by splitting your message field into multiple fields, using an array syntax for the input names:

If you have a primary “Message” field, you should name it message[body], like in that example.

An email sent with the above form might result in the following message:

• Name: John Doe
• Email: [email protected]
• Phone: (555) 123-4567
• Services: Design, Development

Hey guys, I really loved this simple contact form (I'm so tired of agencies
asking for everything but my social security number up front), so I trust
you guys know a thing or two about usability.

I run a small coffee shop and we want to start attracting more freelancer-
types to spend their days working from our shop (and sipping fine coffee!).
A clean new website with lots of social media integration would probably
help us out quite a bit there. Can you help us with that?

Hope to hear from you soon.

Cathy Chino

By default, there’s no restriction on which keys can be included on message. You can limit which fields are allowed using the allowedMessageFields setting in config/contact-form.php:

Overriding plugin settings

If you create a config file in your config/ folder called contact-form.php, you can override the plugin’s settings in the Control Panel. Since that config file is fully multi-environment aware, this is a handy way to have different settings across multiple environments.

Here’s what that config file might look like along with a list of all of the possible values you can override.

Dynamically adding email recipients

You can programmatically add email recipients from your template by adding a hidden input field named toEmail like so:

If you want to add multiple recipients, you can provide a comma separated list of emails like so:

Then from your config/contact-form.php config file, you’ll need to add a bit of logic:

In this example if toEmail does not exist or fails validation (it was tampered with), the plugin will fallback to the “To Email” defined in the plugin settings, so you must have that defined as well.

File attachments

If you would like your contact form to accept file attachments, follow these steps:

  1. Go to Settings → Contact Form in the Control Panel, and make sure the plugin is set to allow attachments.
  2. Make sure your opening HTML <form> tag contains enctype="multipart/form-data".
  3. Add a <input type="file" name="attachment"> to your form.
  4. If you want to allow multiple file attachments, use multiple <input type="file" name="attachment[]" multiple> inputs.

Ajax form submissions

You can optionally post contact form submissions over Ajax if you’d like. Just send a POST request to your site with all of the same data that would normally be sent:

The afterValidate event

Modules and plugins can be notified when a submission is being validated, providing their own custom validation logic, using the afterValidate event on the Submission model:

The beforeSend event

Modules and plugins can be notified right before a message is sent out to the recipients using the beforeSend event. This is also an opportunity to flag the message as spam, preventing it from getting sent:

The afterSend event

Modules and plugins can be notified right after a message is sent out to the recipients using the afterSend event.

Using a “Honeypot” field

Support for the honeypot captcha technique to fight spam has been moved to a separate plugin that complements this one.


All versions of contact-form with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0.2
craftcms/cms Version ^4.0.0-beta.1|^5.0.0-beta.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package craftcms/contact-form contains the following files

Loading the files please wait ....