Skip to content

Commit

Permalink
Merge pull request #41 from jadwigo/emailsanity
Browse files Browse the repository at this point in the history
fallback email addresses for the sender
  • Loading branch information
jadwigo committed Oct 2, 2015
2 parents 5770035 + 582d627 commit 6fd0652
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 93 deletions.
4 changes: 2 additions & 2 deletions Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ protected function getDefaultConfig()
'recaptcha_error_message' => "The CAPTCHA wasn't entered correctly. Please try again.",
'recaptcha_theme' => 'clean',
'csrf' => true,
'from_email' => '[email protected]',
'from_name' => 'Default',
'from_email' => null,
'from_name' => null,
'recipient_cc_email' => '',
'recipient_cc_name' => '',
'recipient_bcc_email' => '',
Expand Down
106 changes: 30 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
Simple Forms
============

The "Simple Forms" extension allows you to insert forms into your templates. Use it by simply placing the following in your template,
with the name of the form to insert:
The "Simple Forms" extension allows you to insert forms into your templates. Use it by simply placing the following in your template, with the name of the form to insert:

{{ simpleform('formname') }}

With SimpleForms you create forms, by defining them in the `extensions/SimpleForms.yml`-file. The file has some general settings,
plus a section with fields for each different form.
With SimpleForms you create forms, by defining them in the `app/extensions/simpleforms.bolt.yml`-file. The file has some general settings, plus a section with fields for each different form.

Installation
------------
The easiest way to install this extension is to go to "View/Install extensions" in the "Extra" menu in your bolt install, type " SimpleForms" into the search box and follow the instructions.
The easiest way to install this extension is to go to "View/Install extensions" in the "Extra" menu in your bolt install, type "SimpleForms" into the search box and follow the instructions.

License
-------
Expand All @@ -21,37 +19,22 @@ Simple Forms is released under the open source [MIT-license](http://opensource.o
General settings
----------------

- `stylesheet: assets/simpleforms.css` - The CSS to display the forms with. If you want to modify the CSS, you should
copy the file to your `theme/` folder, and modify it there. Any changes in the file in the distribution might be
overwritten after an update to the extension.
- `template: assets/simpleforms_form.twig` - The Twig template to display the forms with. If you want to modify the
HTML, you should copy the file to your `theme/` folder, and modify it there. Any changes in the file in the
distribution might be overwritten after an update to the extension. This file uses the
[Symfony Forms component](http://symfony.com/doc/current/book/forms.html#form-theming).
- `mail_template: assets/simpleforms_mail.twig` - The Twig template to format the emails with. If you want to modify
the HTML, you should copy the file to your `theme/` folder, and modify it there. Any changes in the file in the
distribution might be overwritten after an update to the extension.
- `stylesheet: assets/simpleforms.css` - The CSS to display the forms with. If you want to modify the CSS, you should copy the file to your `theme/` folder, and modify it there. Any changes in the file in the distribution might be overwritten after an update to the extension.
- `template: assets/simpleforms_form.twig` - The Twig template to display the forms with. If you want to modify the HTML, you should copy the file to your `theme/` folder, and modify it there. Any changes in the file in the distribution might be overwritten after an update to the extension. This file uses the [Symfony Forms component](http://symfony.com/doc/current/book/forms.html#form-theming).
- `mail_template: assets/simpleforms_mail.twig` - The Twig template to format the emails with. If you want to modify the HTML, you should copy the file to your `theme/` folder, and modify it there. Any changes in the file in the distribution might be overwritten after an update to the extension.
- `message_ok: ...` - The message to display when the form is correctly filled out and was sent to the recipient.
- `message_error: ...` - The message to display when there's an error in one of the form fields.
- `message_technical: ...` - The message to display when there's a technical error preventing the sending of the email.
Most likely this is caused because Swiftmailer can't send the email. Check the Swiftmailer settings in the global
`config.yml` if this message is shown.
- `message_technical: ...` - The message to display when there's a technical error preventing the sending of the email. Most likely this is caused because Swiftmailer can't send the email. Check the Swiftmailer settings in the global `config.yml` if this message is shown.
- `redirect_on_ok: ...` - Instead of simply displaying a message when the form is 'OK', you can also redirect to a different page on the site, for a more extended message after submitting the form. The value should be a `contenttype/id` or `contenttype/slug` pair. For example: `entry/1` or `page/thank-you`.
- `button_text: Send` - Default text on the 'send' button in the forms.
- `recipient_cc_email: [email protected]` - Use this value to set a global cc email address, this email address will receive a copy of
all emails sent with simpleforms.
- `recipient_cc_email: [email protected]` - Use this value to set a global cc email address, this email address will receive a copy of all emails sent with simpleforms.
- `recipient_cc_name: Info` - Use this as the display name for the cc email address.
- `recipient_bcc_email: [email protected]` - Use this value to set a global bcc email address, this email address will receive a blind copy of
all emails sent with simpleforms - this value does not have a display name.
- `testmode: true` - Sets a global testmode, you can use this to for development if you do not want other people to be bothered by
endless testing emails. If you set this value to `true` all email will be sent to the `testmode_recipient` and all other
recipient and cc addresses will be ignored. The default value is false.
- `recipient_bcc_email: [email protected]` - Use this value to set a global bcc email address, this email address will receive a blind copy of all emails sent with simpleforms - this value does not have a display name.
- `testmode: true` - Sets a global testmode, you can use this to for development if you do not want other people to be bothered by endless testing emails. If you set this value to `true` all email will be sent to the `testmode_recipient` and all other recipient and cc addresses will be ignored. The default value is false.
- `debugmode: true` - Sets a global debugmode, the form will output a lot of internal debug information you can use this to for development
- `testmode_recipient: [email protected]` - The email where all test emails should go.

**Tip**: If you want to copy one of the template files, you should remember to leave out the `assets/` part. For
instance, if you copy `simpleforms_form.twig` to `theme/base-2013/my_form.twig`, the corresponding line in `config.yml`
should be:
**Tip**: If you want to copy one of the template files, you should remember to leave out the `assets/` part. For instance, if you copy `simpleforms_form.twig` to `theme/base-2013/my_form.twig`, the corresponding line in `config.yml` should be:

<pre>template: my_form.twig</pre>

Expand All @@ -75,14 +58,9 @@ myformname:
button_text: Send the Demo form!
</pre>

Each form has a name, which is used to insert the correct form in your templates. For example, if you've named your
form `myformname`, as in the example above, you can insert the form in your templates using
`{{ simpleform('myformname') }}`. Use the `recipient_email` and `recipient_info` fields to set the recipients of the
emails. Use the `mail_subject` value to set the subject of the confirmation emails. The optional `button_text` can be
used to override the global setting for the text on the 'send' button.
Each form has a name, which is used to insert the correct form in your templates. For example, if you've named your form `myformname`, as in the example above, you can insert the form in your templates using `{{ simpleform('myformname') }}`. Use the `recipient_email` and `recipient_info` fields to set the recipients of the emails. Use the `mail_subject` value to set the subject of the confirmation emails. The optional `button_text` can be used to override the global setting for the text on the 'send' button.

Each of the 'General settings' mentioned above can be overridden for a specific form. So, you can create forms that use
different templates and different messages.
Each of the 'General settings' mentioned above can be overridden for a specific form. So, you can create forms that use different templates and different messages.

The fields of the form are defined in the `fields`-array. Every field is defined by its name, with its options. For example:

Expand All @@ -95,8 +73,7 @@ The fields of the form are defined in the `fields`-array. Every field is defined
placeholder: Just a quick message ..
</pre>

Make sure the name (in this example `subject`) is unique to the form. Each of the different fieldtypes has a few options
to modify the functionality or appearance:
Make sure the name (in this example `subject`) is unique to the form. Each of the different fieldtypes has a few options to modify the functionality or appearance:

- `class` - The class is passed in the rendered HTML, so it can be used to style the form elements.
- `required` - Whether or not the field is required to be filled in. If omitted, defaults to `false`.
Expand All @@ -106,39 +83,22 @@ to modify the functionality or appearance:
- `allow_override` - If set to `true`, it's possible to override the value in this field using a `GET` parameter in
the URL. For example, if your form has a field `title`, you can override it using `/page/contact/?title=This+is+the+title`.
The form takes care of escaping the input, to prevent XSS.
- `read_only` - Set the field to `readonly` in the generated HTML. (yes, we're aware of the inconsistency between
'read_only' and 'readonly'. 'read_only' is the name of the option in Symfony's Form component, while 'readonly' is
the name of the attribute in the generated HTML)
- `read_only` - Set the field to `readonly` in the generated HTML. (yes, we're aware of the inconsistency between 'read_only' and 'readonly'. 'read_only' is the name of the option in Symfony's Form component, while 'readonly' is the name of the attribute in the generated HTML)
- `prefix` - Add a snippet of HTML to output _before_ the `<div>` with the field's row.
- `postfix` - Add a snippet of HTML to output _after_ the `<div>` with the field's row.
You can use these attributes to insert labels, headings or to divide the form in `<fieldset>`'s.
- `use_as` - Only for email fields, you can use `to_email`, `from_email`, `cc_email` or `bcc_email`
to use the entered email as an extra address.
- `use_with: fieldname` - An optional name for an email field. Use this to reference another field, that will be used
to display the name of the person, used in the `use_as`. Doing this, you can make emails with proper recipients, that
will be shown as `Example person <[email protected]>`. See the 'Email input with extra recipient' example below.
- `minlength` - Add HTML5 form validation minimum length input attribute. Browsers that recognize HTML5 form validation
will not except any input shorter than your entered value. Example: `<input type="text" minlength="5"`
- `maxlength` - Add HTML5 form validation maxlength to your input attribute. Browsers that recognize HTML5 form
validation will not except any input longer than your entered value. Example: `<input type="text" maxlength="25"`
- `autofocus` HTML5 autofocus attribute. On page render the input with `autofocus="on"` will be highlighted. Options
are `autofocus: on` or `autofocus: off`. Only one form element can have the autofocus attribute. It cannot be
applied if the type is `hidden`.
- `expanded: true` Attribute for choice elements, use this in combination with multiple and required to make
select boxes, radio groups or checkbox groups
- `multiple: true` Attribute for choice elements, use this in combination with expanded and required to make
select boxes, radio groups or checkbox groups
- `autocomplete` HTML5 form attribute that turns the in browser autocomplete function on or off. This is ignored if the
input type is set to `hidden`.
- `postfix` - Add a snippet of HTML to output _after_ the `<div>` with the field's row. You can use these attributes to insert labels, headings or to divide the form in `<fieldset>`'s.
- `use_as` - Only for email fields, you can use `to_email`, `from_email`, `cc_email` or `bcc_email` to use the entered email as an extra address.
- `use_with: fieldname` - An optional name for an email field. Use this to reference another field, that will be used to display the name of the person, used in the `use_as`. Doing this, you can make emails with proper recipients, that will be shown as `Example person <[email protected]>`. See the 'Email input with extra recipient' example below.
- `minlength` - Add HTML5 form validation minimum length input attribute. Browsers that recognize HTML5 form validation will not except any input shorter than your entered value. Example: `<input type="text" minlength="5"`
- `maxlength` - Add HTML5 form validation maxlength to your input attribute. Browsers that recognize HTML5 form validation will not except any input longer than your entered value. Example: `<input type="text" maxlength="25"`
- `autofocus` HTML5 autofocus attribute. On page render the input with `autofocus="on"` will be highlighted. Options are `autofocus: on` or `autofocus: off`. Only one form element can have the autofocus attribute. It cannot be applied if the type is `hidden`.
- `expanded: true` Attribute for choice elements, use this in combination with multiple and required to make select boxes, radio groups or checkbox groups
- `multiple: true` Attribute for choice elements, use this in combination with expanded and required to make select boxes, radio groups or checkbox groups
- `autocomplete` HTML5 form attribute that turns the in browser autocomplete function on or off. This is ignored if the input type is set to `hidden`.
* `off`: must explicitly enter a value into this field for every use. the browser does not automatically complete the entry.
* `on`: The browser can automatically complete the value based on values that the user has entered during previous uses.
- `pattern` A JavaScript regular expression to check the input field against. This attribute applies to fields with a type
of `text`, `search`, `tel`, `url` or `email`.
Example alphanumeric: `<input type="text" pattern="^[a-zA-Z0-9]+" />`
- `pattern` A JavaScript regular expression to check the input field against. This attribute applies to fields with a type of `text`, `search`, `tel`, `url` or `email`. Example alphanumeric: `<input type="text" pattern="^[a-zA-Z0-9]+" />`


The different fieldtypes are as follows, with a short example outlining the specific options for that field.
Remember you can also use the basic options as well.
The different fieldtypes are as follows, with a short example outlining the specific options for that field. Remember you can also use the basic options as well.

**Standard text input:**

Expand Down Expand Up @@ -191,16 +151,12 @@ Remember you can also use the basic options as well.
type: date
format: "Y-m-d"

The `format` option is used for formatting the date in the emails. You can use the options that are available in
PHP's `date()` function. See the [documentation for details](http://php.net/date).
The `format` option is used for formatting the date in the emails. You can use the options that are available in PHP's `date()` function. See the [documentation for details](http://php.net/date).

Using ReCaptcha field:
----------------------

To protect your forms from spam-bots, you can enable the ReCaptcha service. This lets the visitors type out two words or
numbers from a picture, to prove that they're human. To enable ReCaptcha, simply enable/fill all the <code>recaptcha_</code>
fields in <code>config.yml</code>. If you don't have a private/public keypair yet, go to
[this URL](https://www.google.com/recaptcha/admin/create) to create them.
To protect your forms from spam-bots, you can enable the ReCaptcha service. This lets the visitors type out two words or numbers from a picture, to prove that they're human. To enable ReCaptcha, simply enable/fill all the <code>recaptcha_</code> fields in <code>config.yml</code>. If you don't have a private/public keypair yet, go to [this URL](https://www.google.com/recaptcha/admin/create) to create them.

Overriding values
-----------------
Expand All @@ -215,11 +171,9 @@ This will prefill the field named `somefield` with `somevalue`. This is always a
Email input with extra recipient:
---------------------------------

If you want to send a copy of the an email address the visitor entered, you can use the `use_as` and
`use_with` options for email and text fields.
If you want to send a copy of the an email address the visitor entered, you can use the `use_as` and `use_with` options for email and text fields.

You can define as many email fields as you like and the addresses will be used, you need to add the
`use_with` option for each field if you want nice display names.
You can define as many email fields as you like and the addresses will be used, you need to add the `use_with` option for each field if you want nice display names.

recipient:
type: email
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
"bolt/bolt" : ">=2.0.0,<3.0.0",
"bolt/boltforms" : "^2.4"
},
"require-dev" : {
"phpunit/phpunit" : "^4.7"
},
"repositories" : [{
"type" : "composer",
"name" : "bolt",
Expand Down
13 changes: 0 additions & 13 deletions config.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@ demo:
recipient_name: Info
recipient_cc_email: [email protected]
recipient_cc_name: Another Email Address
# if you want to save form content to a database make a table with the exact column names and types of your fields
insert_into_table: bolt_your_table_name
# uploaded files will be saved here if you have a file field
storage_location: demo_uploads
# uploaded files attached to the email if true
attach_files: true
fields:
subject:
type: text
Expand Down Expand Up @@ -111,13 +105,6 @@ demo:
empty_value: My favorite animals are
choices: [ Kittens, Puppies, Penguins, Koala bears, "I don't like animals" ]
required: true
file:
type: file
label: Upload a file
required: true
filetype: [jpg, gif, tiff, png, pdf]
#mimetypes are optional, used by Symfony Forms Validator
mimetype: ["application/pdf", "application/x-pdf", "image/tiff", "image/x-tiff", "image/png", "image/jpeg", "image/pjpeg", "image/gif"]
option1:
type: checkbox
label: Newsletter
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigurationBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ protected function convertFormConfig($formName, array $config)
'enabled' => 'true',
'debug' => $config['testmode'],
'subject' => isset($fields['mail_subject']) ? $fields['mail_subject'] : 'Your message was submitted',
'from_name' => isset($fields['from_name']) ? $fields['from_name'] : null,
'from_email' => isset($fields['from_email']) ? $fields['from_email'] : null,
'from_name' => isset($fields['from_name']) ? $fields['from_name'] : $config['from_name'],
'from_email' => isset($fields['from_email']) ? $fields['from_email'] : $config['from_email'],
'replyto_name' => isset($fields['recipient_name']) ? $fields['recipient_name'] : null,
'replyto_email' => isset($fields['replyto_email']) ? $fields['replyto_email'] : null,
'to_name' => isset($fields['recipient_name']) ? $fields['recipient_name'] : null,
Expand Down
Loading

0 comments on commit 6fd0652

Please sign in to comment.