@comconnect@, to create a form that is initially hidden by setting the @sendarticle@ attribute.

February 28, 2024 · View on GitHub

h1. com_connect

h2. Contents

  • "Introduction":#introduction
  • "Installing and upgrading":#install
  • "Migrating from zem_contact_reborn":#differences
  • "Usage":#usage
  • "Tags":#tags ** "com_connect tag":#cc ** "com_connect_text tag":#cc_text ** "com_connect_email tag":#cc_email ** "com_connect_textarea tag":#cc_textarea ** "com_connect_submit tag":#cc_submit ** "com_connect_select tag":#cc_select ** "com_connect_option tag":#cc_option ** "com_connect_checkbox tag":#cc_checkbox ** "com_connect_radio tag":#cc_radio ** "com_connect_secret tag":#cc_secret ** "com_connect_serverinfo tag":#cc_serverinfo ** "com_connect_send_article tag":#cc_send_article ** "com_connect_mime tag":#cc_mime ** "com_connect_fields tag":#cc_fields ** "com_connect_label tag":#cc_label ** "com_connect_value tag":#cc_value ** "com_connect_if tag":#cc_if
  • "Advanced examples":#advanced ** "Separate input and error forms":#advanced1 ** "User selectable subject field":#advanced2 ** "User selectable recipient, without showing email address":#advanced3
  • "Styling":#styling
  • "Plugin API and callback events":#api
  • "Frequently asked questions":#faq
  • "Authors/credits":#credits

h2(#introduction). Introduction

A Textpattern CMS form mailer plugin. @<txp:com_connect />@ produces a flexible, customisable email contact form. It is intended for use as an enquiry form for commercial and private sites, and includes several features to help reduce common problems with such forms (invalid email addresses, missing information).

Please report bugs and problems with this plugin at "the GitHub project's issues page":https://github.com/textpattern/com_connect/issues.

h3. Features

  • Arbitrary HTML5 text fields can be specified, with min/max/required settings for validation.
  • Email address validation, including a check for a valid MX record (Unix only).
  • Safe escaping of input data.
  • UTF-8 safe.
  • Accessible form layout, including @
  • Various classes and ids to allow easy styling of all parts of the form.
  • Spam prevention API (used by Tranquillo's @pap_contact_cleaner@ plugin) and delivery API for altering or extending the plugin's capabilities.

h3. History

Please see the "changelog on GitHub":https://github.com/textpattern/com_connect/blob/main/CHANGELOG.textile.

h2(#install). Installing and upgrading

Requires Textpattern 4.7.0+

Download the latest release of the plugin from "the GitHub project page":https://github.com/textpattern/com_connect/releases, paste the code into the Textpattern Admin>Plugins panel, install and enable the plugin. Visit the "forum thread":https://forum.textpattern.io/viewtopic.php?id=47913 for more info or to report on the success or otherwise of the plugin.

To uninstall, delete from the Plugins panel.

Alternatively, this plugin can be installed using "Composer":https://getcomposer.org:

bc(language-bash). $ composer require textpattern/com_connect:*

h2(#differences). Migrating from zem_contact_reborn

If upgrading from zem_contact_reborn (the previous incarnation of this plugin), please note these differences:

  • Tags have been globally renamed from @<txp:zem_contact ... />@ to @<txp:com_connect ... />@ - please adjust your code accordingly.
  • Classes @zemConnectForm@, @zemError@, @zemRequired@, @zemThanks@, @zemText@, @zemEmail@, @zemTextarea@, @zemSubmit@, @zemSelect@, @zemOption@, @zemCheckbox@ and @zemRadio@ have been renamed to @comConnectForm@, @comError@, @comRequired@, @comThanks@, @comText@, @comEmail@, @comTextarea@, @comSubmit@, @comSelect@, @comOption@, @comCheckbox@ and @comRadio@ respectively - please adjust your code accordingly.
  • Disable or remove the zem_contact_lang plugin. Language strings are now bundled as part of the plugin itself. If you have a translation Textpack available that is not yet bundled, please submit it for inclusion.
  • Classes based on the input element @name@ are no longer automatically applied. Only default class names beginning with @com@ are set. To employ custom classes, use the @class@ attribute for each tag, or the global @classes@ attribute to set names for error and information messages.
  • If your site's 'Doctype' preference is set to @html5@ you may use HTML5 attributes in your tags. Otherwise, they will be ignored.
  • Validation of required elements and min/max constraints is done by the browser first, and the plugin second. So if you specify a field is required and it is left empty, the browser will usually prevent the form being submitted. To bypass (most of) the browser checks, specify @browser_validate="0"@ in your @<txp:com_connect />@ tag.

h2(#usage). Usage

h3. Contact form

The simplest form is shown below, which produces a default form with 'Name', 'Email' and 'Message' fields. Email will be delivered to recipient@example.com, with the user's supplied email as the @From:@ address.

bc(language-markup). <txp:com_connect to="recipient@example.com" />

To specify fields explicitly, use something like this:

bc(language-markup). <txp:com_connect to="recipient@example.com"> <txp:com_connect_email /> <txp:com_connect_text label="Phone" min="7" max="15" /> <txp:com_connect_textarea label="Your question" /> <txp:com_connect_submit label="Send" /> </txp:com_connect>

Alternatively, place the field specifications in a Textpattern form, and call it like this:

bc(language-markup). <txp:com_connect to="recipient@example.com" form="my-contact-form" />

h3. Send article

Within the context of an individual article, this plugin can be used to send the article (or excerpt, if it exists) to an email address specified by the visitor. This requires at least two tags:

@com_connect@, to create a form that is initially hidden by setting the @send_article@ attribute.

@com_connect_send_article@, to create a 'Send article' link which reveals the aforementioned form when clicked.

bc(language-markup). <txp:com_connect send_article="1" /> <txp:com_connect_send_article />

By default the form contains fields for your name and email address, the recipient's email address and a personal message, but similar to contact forms you can create your own form layout. Some things you need to know:

Set the @send_article@ attribute to @1@ in the @com_connect@ tag.

Use a @com_connect_email@ tag with the @send_article@ attribute set to @1@. This field will be used as the recipient email address.

bc(language-markup).. <txp:com_connect to="you@example.com" send_article="1"> <txp:com_connect_email label="Recipient Email" send_article="1" /> <txp:com_connect_email label="Your Email" /> <txp:com_connect_submit label="Send Article" /> </txp:com_connect>

<txp:com_connect_send_article />

h2(#tags). Tags

@<txp:com_connect_send_article />@ can be used to create a 'Send article' link within an article form, connecting it to the contact form.

All other tags provided by this plugin can only be used inside a @txp:com_connect@ - @</txp:com_connect>@ container tag or in a Textpattern form used as the @form@ attribute in the @<txp:com_connect />@ tag.

In addition to the tags detailed in the following sections, every tag accepts a core set of common attributes. These are:

; @accesskey="character"@ : Shortcut key to set focus on the field. ; @autofocus="boolean"@ : To automatically focus the cursor in this field on page load. Only one field may have this property. ; @dir="value"@ : Text direction (@ltr@, @rtl@ or @auto@). ; @disabled="boolean"@ : Whether the input control accepts user input. If set, the element does not get submitted with the form, nor is it subject to any @checkValidity()@ JavaScript calls. ; @hidden="boolean"@ : The visibility of the input control. ; @id="id"@ : The HTML identifier for the control. ; @lang="value"@ : The ISO 639 language short code (e.g. @en-gb@, @de-de@) that governs the field. ; @list="id"@ : Used in conjunction with the @@ tag to specify a set of options. The id is the reference to the datalist to use. ; @readonly="boolean"@ : Control does not accept user input, but will be processed on form submission and can be validated. ; @spellcheck="value"@ : Whether the field is subject to spell checking (@true@ = yes, @default@ = browser decides, or @false@ = no). ; @style="style rules"@ : Inline CSS @style@ rules to apply to the input control. ; @tabindex="number"@ : The order in which the cursor jumps between elements when using the tab key. ; @title="value"@ : Usually used for hover tooltip describing the input control's use in your application. ; @translate="boolean"@ : Whether to subject the attribute content to language translation.

h3(#cc). com_connect tag

bc(language-markup). <txp:com_connect />

May be used as a single (self-closing) or container tag. Place this where you want the input form to go. Status and error messages, if any, will be displayed before the form.

h4. Attributes

; @body_form="form name"@ : Use specified form for the message body text. ; @class="space-separated values"@ : Set the CSS @class@ name of the tag. Default: @comConnectForm@. To remove @class@ attribute from the element entirely, use @class=""@. ; @classes="comma-separated key:value pairs"@ : Set the CSS classes for error / information conditions. Specify each as a pair of values separated by a colon, e.g. @classes="required: req_field, element: warn_field"@. There are up to four available to customise: : @element@: Set for each form field that fails validation for any reason. Default: @errorElement@. : @wrapper@: The class to surround the list of errors shown above the form. Default: @comError@. : @required@: Class assigned when a required element is not completed. Default: @comRequired@. : @thanks@: Class applied to the wrapper around the @thanks_form@. Default: @comThanks@. ; @copysender="boolean"@ : Whether to send a copy of the email to the sender's address. Available values: @1@ (yes) or @0@ (no). Default is @0@. ; @expire="number"@ : Number of seconds after which the form will expire, thus requiring a page refresh before sending. Default is @600@. ; @form="form name"@ : Use specified form, containing the layout of the contact form fields. ; @from="email address"@ : Email address used in the "From:" field when sending email. Defaults to the sender's email address. If specified, the sender's email address will be placed in the "Reply-To:" field instead. ; @from_form="form name"@ : Use specified form (overrides @from@ attribute). ; @label="text"@ : Label for the contact form. If set to an empty string, display of the fieldset and legend tags will be suppressed. Default is @Contact@. ; @lang="lang-code"@ : Override the language strings that would normally be used from the current admin-side language in force. e.g. @lang="fr-fr"@ would load the French language strings. A Textpack must already exist for the chosen language. ; @browser_validate="boolean"@ : Set to 0 if you wish to stop the browser from validating form field values and 'required' status of input elements. The plugin itself is then solely responsible for validation and will indicate error conditions after submission. Default is @1@. ; @redirect="URL"@ : Redirect to specified URL (overrides @thanks@ and @thanks_form@ attributes). URL must be relative to the Textpattern site URL. Example: @redirect="monkey"@ would redirect to @http://example.com/monkey@. ; @replyto=boolean|email address@ : Governs the email address of who the message reply should go to. Options: : @true@ (default): Use the email address from the form itself (value from the @txp:com_connect_email@ tag) if the @from@ address has been specified. Blank otherwise. : @false@: Always use the @from@ email address as reply-to. Note that if the @from@ is omitted the email will be from nobody and may be rejected by the receiving server. : @email address@: Use the specified email address as the reply-to, if it's a valid address. ; @required="boolean"@ : Whether to require all tags in this contact form to be completed before the form can be submitted. Can be overridden on a field-by-field basis by using the @required@ attribute in the relevant tag. Available values: @1@ (yes) or @0@ (no). Default is @1@. ; @send_article="boolean"@ : Whether to use this form to send an article. Available values: @1@ (yes) or @0@ (no). Default is @0@. ; @show_error="boolean"@ : Whether to display error and status messages. Available values: @1@ (yes) or @0@ (no). Default is @1@. ; @show_input="boolean"@ : Whether to display the form @@ fields. Available values: @1@ (yes) or @0@ (no). Default is @1@. ; @subject="subject text"@ : Subject used when sending an email. Default is the site name. ; @subject_form="form name"@ : Use specified form (overrides @subject@ attribute). ; @thanks="text"@ : Message shown after successfully submitting a message. Default is @Thank you, your message has been sent@. ; @thanks_form="form name"@ : Use specified form (overrides @thanks@ attribute). ; @to="email address"@ %(warning)required% : Recipient email address. Multiple recipients can be specified, separated by commas. ; @to_form="form name"@ : Use specified form (overrides @to@ attribute).

h4. Examples

h5. Example 1: Built-in contact form

When used as a single tag, produces a default form with 'Name', 'Email' and 'Message' fields. Email will be delivered to recipient@example.com, with the user's supplied email as the @From:@ address:

bc(language-markup). <txp:com_connect to="recipient@example.com" />

h5. Example 2: Building a custom form container

When used as a container tag, much more flexibility is allowed, for example:

bc(language-markup). <txp:com_connect to="recipient@example.com"> <txp:com_connect_email /> <txp:com_connect_text type="tel" label="Phone" min="7" max="15" /> <txp:com_connect_textarea label="Your question" /> <txp:com_connect_submit label="Send" /> </txp:com_connect>

h5. Example 3: Custom message formatting

Use the @body_form@ attribute to build custom content that is emailed to the recipient:

bc(language-markup). <txp:com_connect to="recipient@example.com" body_form="message-formatting" />

And the @body_form@ form template named @message-formatting@ is as follows:

bc.. ============ Email received.

<txp:com_connect_if name="email"><txp:com_connect_label name="email" />: <txp:com_connect_value name="email" /><txp:else />Mr. Nobody</txp:com_connect_if> wrote:

<txp:com_connect_if name="message"><txp:com_connect_value name="message" /><txp:else />Nothing much :(</txp:com_connect_if>

============

h5. Example 4: HTML and plaintext email content

Use the @body_form@ attribute to build custom content in both plaintext and HTML formats that is emailed to the recipient:

bc(language-markup). <txp:com_connect to="recipient@example.com" body_form="message-formatting" />

Use the @body_form@ form template named @message-formatting@ as follows, and note the @txp:com_connect_mime@ tags which indicate that the content of the given @type@ immediately follows. Use the tag with @type="end"@ to signify that the content is complete.

bc.. ============ <txp:com_connect_mime type="text" /> Fields submitted: <txp:com_connect_fields break=""> <txp:com_connect_label />: <txp:com_connect_value /> </txp:com_connect_fields>

<txp:com_connect_mime type="html" />

<txp:com_connect_mime type="end" />

h3(#cc_text). com_connect_text tag

bc(language-markup). <txp:com_connect_text />

Creates a text @@ field and corresponding @

h4. Attributes

; @autocomplete="value"@ : Indicates whether the value of the control can be automatically completed by the browser. This attribute is ignored if the value of the type attribute is @password@. Possible values are: @off@ (the browser does not automatically complete the entry) or @on@ (the browser can automatically complete the value based on values that the user has entered during previous uses). Default is unset. ; @break="tag"@ : Break tag between the @

@ tag to which the field is attached. Associated with the contained form by default. ; @inputmode="value"@ : A hint to the browser for which keyboard to display. This attribute applies when the value of the type attribute is @text@, @password@ or @url@. Possible values are: : @verbatim@: Alphanumeric, non-prose content such as usernames and passwords. : @latin@: Latin-script input in the user's preferred language with typing aids such as text prediction enabled. For human-to-computer communication such as search boxes. : @latin-name@: As latin, but for human names. : @latin-prose@: As latin, but with more aggressive typing aids. For human-to-human communication such as instant messaging for email. : @full-width-latin@: As latin-prose, but for the user's secondary languages. : @kana@: Kana or romaji input, typically hiragana input, using full-width characters, with support for converting to kanji. Intended for Japanese text input. : @katakana@: Katakana input, using full-width characters, with support for converting to kanji. Intended for Japanese text input. : @numeric@: Numeric input, including keys for the digits 0 to 9, the user's preferred thousands separator character, and the character for indicating negative numbers. Intended for numeric codes, e.g. credit card numbers. For actual numbers, prefer using @type="number"@. : @tel@: Telephone input, including asterisk and pound key. Use @type="tel"@ if possible instead. : @email@: Email input. Use @<txp:com_connect_email />@ if possible instead. : @url@: URL input. Use @type="url"@ if possible instead. ; @label="text"@ : Text label displayed to the user. Default is @Text@. ; @label_position="text"@ : Position of the label in relation to the @@ field. Available values: @before@ or @after@. Default is @before@. ; @max=value"@ : For character-based inputs, the maximum input value length in characters, using the HTML5 @maxlength@ attribute. To remove @maxlength@ attribute from the element entirely (not recommended), use @max=""@. For numeric-based inputs, the maximum input value the field accepts, using the HTML5 @max@ attribute (can be a negative value). Default is @100@. To remove @max@ attribute from the numerical input element entirely, use @max=""@. ; @min="value"@ : For character-based inputs, the minimum input value length in characters, using the HTML5 @minlength@ attribute. Default is unset, i.e., no minimum limit. For numeric-based inputs, the minimum input value the field accepts, using the HTML5 @min@ attribute (can be a negative value). Default is @0@. To remove @min@ attribute from the numerical input element entirely, use @min=""@. ; @name="value"@ : Field name, as used in the HTML @@ tag. ; @pattern="regex"@ : Regular expression that governs the format in which the field data is expected. Only used for character-based inputs. ; @placeholder="text"@ : Text to show as a guide, when the @@ field is empty. ; @required="boolean"@ : Whether this field must be filled out. Available values: @1@ (yes) or @0@ (no). Default is whatever is set in the @txp:com_connect@ tag's @required@ attribute - if neither attribute is set then default is @1@. ; @size="value"@
The size, in characters, of the @@ field. ; @step="value"@ : For numeric-based inputs, the interval between min and max. ; @type="value"@ : Type of text input. Default is @text@. Choose from: : @color@ : @date@ : @datetime@ : @datetime-local@ : @month@ : @number@ : @password@ : @range@ : @search@ : @tel@ : @text@ : @time@ : @url@ : @week@

h4. Examples

h5. Example 1: Text input box

bc(language-markup). <txp:com_connect_text label="Your name" />

h5. Example 2: Range slider

bc(language-markup). <txp:com_connect_text type="range" label="UK shoe size" min="1" max="15" />

h5. Example 3: Telephone input with validation

Create a telephone field with a "validation pattern for UK telephone number":http://html5pattern.com/Phones format:

bc(language-markup). <txp:com_connect_text type="tel" label="Telephone" pattern="^\s*(?(020[7,8]{1})?[ ]?[1-9]{1}[0-9{2}[ ]?[0-9]{4})|(0[1-8]{1}[0-9]{3})?[ ]?[1-9]{1}[0-9]{2}[ ]?[0-9]{3})\s*$" required="1" />

h3(#cc_email). com_connect_email tag

bc(language-markup). <txp:com_connect_email />

@@ field for user's email address.

The entered email address will automatically be validated to make sure it is of the form "abc@xxx.yyy[.zzz]". On non-Windows servers, a test will be done to verify that an A or MX record exists for the domain. Neither test prevents spam, but it does help detect accidental typing errors.

h4. Attributes

; @autocomplete="value"@ : Indicates whether the value of the control can be automatically completed by the browser. Possible values are: @off@ (the browser does not automatically complete the entry) or @on@ (the browser can automatically complete the value based on values that the user has entered during previous uses). Default is unset. ; @break="tag"@ : Break tag between the @

h4. Examples

h5. Example 1: Standard email field

bc(language-markup). <txp:com_connect_email label="Your email address" />

h3(#cc_textarea). com_connect_textarea tag

bc(language-markup). <txp:com_connect_textarea />

Creates a @

h4. Attributes

; @autocomplete="value"@ : Indicates whether the value of the control can be automatically completed by the browser. Possible values are: @off@ (the browser does not automatically complete the entry) or @on@ (the browser can automatically complete the value based on values that the user has entered during previous uses). Default is unset. ; @break="tag"@ : Break tag between the @

h4. Examples

h5. Example 1: Standard textarea

Create a text area that is 40 characters wide, 10 lines high, with a customised label:

bc(language-markup). <txp:com_connect_textarea cols="40" rows="10" label="Your question" />

h3(#cc_submit). com_connect_submit tag

bc(language-markup). <txp:com_connect_submit />

Creates a submit button. When used as a container tag, a @