├── _config.php ├── codecov.yml ├── code-of-conduct.md ├── docs ├── images │ ├── extra-image-1.png │ ├── extra-image-2.png │ ├── extra-image-3.png │ ├── global-settings.png │ ├── page-layout-001.png │ ├── page-layout-002.png │ ├── page-layout-003.png │ ├── page-layout-004.png │ ├── page-layout-005.png │ ├── choose-page-type.png │ ├── override-form-ss.png │ ├── page-layout-00101.png │ ├── select-page-layout.png │ ├── view-contact-us-data.png │ ├── set-up-google-recaptcha.png │ ├── contact-us-form-settings.png │ ├── custom-my-own-template-file.png │ └── set-up-google-recaptcha-v3.png └── en │ ├── installing.md │ └── using.md ├── _config └── config.yml ├── contributing.md ├── templates ├── Includes │ ├── CustomLayoutPage3.ss │ ├── CustomLayoutPage1.ss │ ├── CustomLayoutPage2.ss │ ├── CustomLayoutPage5.ss │ ├── CustomLayoutPageContent.ss │ ├── ContactUsCustomFormCode.ss │ ├── CustomLayoutPage4.ss │ ├── ContactUsCustomForm1.ss │ ├── ContactUsCustomForm2.ss │ ├── ContactUsCustomForm3.ss │ └── ContactUsCustomForm4.ss └── SSCustomPageWithContactUsForm │ ├── Layout │ └── CustomLayoutPage.ss │ ├── Page.ss │ └── Email │ └── ContactUsEmail.ss ├── src ├── ContactUsController.php ├── ContactUsAdmin.php ├── CustomLayoutPageController.php ├── ContactUs.php ├── CustomLayoutPage.php └── ContactUsForm.php ├── .editorconfig ├── code └── extentions │ └── CustomPageLayoutConfig.php ├── composer.json ├── license.md └── README.md /_config.php: -------------------------------------------------------------------------------- 1 | 2 |
3 |

$Title

4 |
5 | 6 |
7 |
8 | <% include CustomLayoutPageContent %> 9 |
10 |
11 | <% include ContactUsCustomFormCode %> 12 |
13 |
-------------------------------------------------------------------------------- /src/ContactUsController.php: -------------------------------------------------------------------------------- 1 | owner, 'ContactUsForm'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /templates/Includes/CustomLayoutPage1.ss: -------------------------------------------------------------------------------- 1 |
2 |
3 |

$Title

4 |
5 |
6 |
7 |
8 | <% include CustomLayoutPageContent %> 9 |
10 | <% if FormEnable %> 11 |
12 | <% include ContactUsCustomFormCode %> 13 |
14 | <% end_if %> 15 |
16 | 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # For more information about the properties used in this file, 2 | # please see the EditorConfig documentation: 3 | # http://editorconfig.org 4 | 5 | [*] 6 | charset = utf-8 7 | end_of_line = lf 8 | indent_size = 4 9 | indent_style = space 10 | insert_final_newline = true 11 | trim_trailing_whitespace = true 12 | 13 | [*.{yml,js,json,css,scss,feature,eslintrc}] 14 | indent_size = 2 15 | indent_style = space 16 | 17 | [composer.json] 18 | indent_size = 4 -------------------------------------------------------------------------------- /templates/Includes/CustomLayoutPage2.ss: -------------------------------------------------------------------------------- 1 |
2 |
3 |

$Title

4 |
5 |
6 |
7 | <% if FormEnable %> 8 |
9 | <% include ContactUsCustomFormCode %> 10 |
11 | <% end_if %> 12 |
13 | <% include CustomLayoutPageContent %> 14 |
15 |
16 | -------------------------------------------------------------------------------- /src/ContactUsAdmin.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 | <% if PageLayout =='1' %> 5 | <% include CustomLayoutPage1 %> 6 | <% else_if PageLayout =='2' %> 7 | <% include CustomLayoutPage2 %> 8 | <% else_if PageLayout =='3' %> 9 | <% include CustomLayoutPage3 %> 10 | <% else_if PageLayout =='4' %> 11 | <% include CustomLayoutPage4 %> 12 | <% else_if PageLayout =='5' %> 13 | <% include CustomLayoutPage5 %> 14 | <% else_if PageLayout =='101' %> 15 | $loadCustomTemplate.RAW 16 | <% else %> 17 | $CustomLayoutPage1 18 | <% end_if %> 19 | 20 |
21 | $showGoogleRecaptcha.RAW 22 | -------------------------------------------------------------------------------- /templates/Includes/CustomLayoutPage5.ss: -------------------------------------------------------------------------------- 1 |
2 |
3 |

$Title

4 |
5 |
6 |
7 |
8 | $Content 9 |
10 |
11 | $ExtraContent1 12 |
13 |
14 | $ExtraContent2 15 |
16 |
17 | $ExtraContent3 18 |
19 |
20 | 21 | <% if FormEnable %> 22 |
23 |
24 | <% include ContactUsCustomFormCode %> 25 |
26 |
27 | <% end_if %> 28 | -------------------------------------------------------------------------------- /templates/Includes/CustomLayoutPageContent.ss: -------------------------------------------------------------------------------- 1 |
2 | $Content 3 |
4 |
5 | $ExtraText1 6 |
7 |
8 | $ExtraImage1 9 |
10 |
11 | $ExtraContent1 12 |
13 |
14 | $ExtraText2 15 |
16 |
17 | $ExtraImage2 18 |
19 |
20 | $ExtraContent2 21 |
22 |
23 | $ExtraText3 24 |
25 |
26 | $ExtraImage3 27 |
28 |
29 | $ExtraContent3 30 |
-------------------------------------------------------------------------------- /templates/Includes/ContactUsCustomFormCode.ss: -------------------------------------------------------------------------------- 1 | 2 | 3 | <% if Action = success %> 4 |
5 |

$SuccessTitle

6 | $SuccessText 7 |
8 | <% else_if Action = error %> 9 |
$ErrorMessage
10 | <% else_if FormEnable %> 11 |
12 | <% if FormLayout =='1' %> 13 | <% include ContactUsCustomForm1 %> 14 | <% else_if FormLayout =='2' %> 15 | <% include ContactUsCustomForm2 %> 16 | <% else_if FormLayout =='3' %> 17 | <% include ContactUsCustomForm3 %> 18 | <% else_if FormLayout =='4' %> 19 | <% include ContactUsCustomForm4 %> 20 | <% else %> 21 | $ContactUsForm 22 | <% end_if %> 23 |
24 | <% end_if %> 25 | -------------------------------------------------------------------------------- /code/extentions/CustomPageLayoutConfig.php: -------------------------------------------------------------------------------- 1 | 'Varchar', 13 | 'GoogleRecaptchaSiteKey' => 'Varchar', 14 | 'GoogleRecaptchaSecretKey' => 'Varchar', 15 | ]; 16 | 17 | public function updateCMSFields(FieldList $fields) 18 | { 19 | 20 | $fields->addFieldsToTab("Root.Main", [ 21 | TextField::create("ContactUsEmail", "Contact Us Notification Email"), 22 | 23 | TextField::create('GoogleRecaptchaSiteKey', 'Recaptcha Site Key')->setDescription(' 24 | Avoid spam by adding Google Recaptcha v2 or v3 to Contact Us Form'), 25 | TextField::create('GoogleRecaptchaSecretKey', 'Recaptcha Secret Key')->setDescription('Get the key from https://www.google.com/recaptcha') 26 | ]); 27 | } 28 | } -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "alexstack/silverstripe-custom-page-with-contact-us-form", 3 | "description": "SilverStripe Custom Layout Page with Contact Us Form & flexible frontend with Google Recaptcha.", 4 | "type": "silverstripe-vendormodule", 5 | "homepage": "https://github.com/AlexStack/SilverStripe-Custom-Layout-Page-with-Contact-Us-Form/", 6 | "keywords": ["silverstripe", "custom-layout","contact-form", "contact-us", "contact-us-form", "form", "contact", "module", "contact us", "contact form", "contact us form", "custom form"], 7 | "license": "BSD-3-Clause", 8 | "support": { 9 | "issues": "https://github.com/AlexStack/SilverStripe-Custom-Layout-Page-with-Contact-Us-Form/issues" 10 | }, 11 | "authors": [{ 12 | "name": "Alex", 13 | "homepage": "https://github.com/AlexStack/" 14 | }], 15 | "require": { 16 | "silverstripe/cms": "~4.0", 17 | "silverstripe/framework": "~4.0", 18 | "silverstripe/vendor-plugin": "^1.0", 19 | "alexstack/google-recaptcha-to-any-form": "^1.1.1" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "SSCustomPageWithContactUsForm\\": "src/" 24 | } 25 | }, 26 | "minimum-stability": "dev" 27 | } 28 | -------------------------------------------------------------------------------- /templates/SSCustomPageWithContactUsForm/Page.ss: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <% base_tag %> 5 | 6 | 7 | 8 | <% if $URLSegment == 'home' %>$SiteConfig.Title<% else %><% if $MetaTitle %>$MetaTitle<% else %>$Title<% end_if %> - $SiteConfig.Title<% end_if %> 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | $Layout 18 | 19 |
20 |
21 |

Note

22 |

You can override this with your own .ss template. document is here!

23 |
24 |
25 | 26 |
27 | 28 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2019 Alex. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 4 | 5 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 6 | 7 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | 9 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 10 | 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /templates/Includes/CustomLayoutPage4.ss: -------------------------------------------------------------------------------- 1 |
2 |
3 |

$Title

4 |
5 |
6 |
7 |
8 |
9 | $Content 10 |
11 |
12 |
13 | 14 |
15 |
16 |
17 | 18 |
19 |
20 |
21 |

22 | $ExtraText1 23 |

24 |
25 |
26 | $ExtraContent1 27 |
28 |
29 |
30 |
31 |
32 | 33 |
34 |
35 |
36 |

37 | $ExtraText2 38 |

39 |
40 |
41 | $ExtraContent2 42 |
43 |
44 |
45 |
46 |
47 | 48 |
49 |
50 |
51 |

52 | $ExtraText3 53 |

54 |
55 |
56 | $ExtraContent3 57 |
58 |
59 |
60 |
61 | 62 | 63 | 64 | 65 | <% if FormEnable %> 66 |
67 |
68 | <% include ContactUsCustomFormCode %> 69 |
70 |
71 | <% end_if %> 72 | 73 | -------------------------------------------------------------------------------- /templates/Includes/ContactUsCustomForm1.ss: -------------------------------------------------------------------------------- 1 |
8 | 13 | 14 |
15 | $displayFormField('FirstName', 'First Name','showLabel', 'required="required"','mb-3').RAW 16 | 17 | $displayFormField('LastName', 'Last Name','showLabel', 'required="false"','mb-3').RAW 18 | 19 | $displayFormField('Email', 'Email','showLabel','type="email" required="required"','mb-3').RAW 20 | 21 | $displayFormField('Phone', 'Phone Number','showLabel','type="text" ','mb-3').RAW 22 | 23 | $displayFormField('Mobile', 'Mobile Number','showLabel','type="text" ','mb-3').RAW 24 | 25 | $displayFormField('Company', 'Company Name','showLabel','type="text" ','mb-3').RAW 26 | 27 | $displayFormField('Website', 'Website','showLabel','type="text" ','mb-3').RAW 28 | 29 | $displayFormField('Address', 'Address','showLabel','type="text" ','mb-3').RAW 30 | 31 | $displayFormField('Street', 'Street','showLabel','type="text" ','mb-3').RAW 32 | 33 | $displayFormField('PostalCode', 'Postal Code','showLabel','type="text" ','mb-3').RAW 34 | 35 | $displayFormField('City', 'City','showLabel','type="text" ','mb-3').RAW 36 | 37 | $displayFormField('State', 'State','showLabel','type="text" ','mb-3').RAW 38 | 39 | $displayFormField('Country', 'Country','showLabel','type="text" ','mb-3').RAW 40 | 41 | $displayFormField('Subject', 'Subject','showLabel','type="text" ','mb-3').RAW 42 | 43 | $displayFormField('Message', 'Message','showLabel','type="textarea" required="required" minlength="6" rows="8" cols="20"','textarea-class w-100').RAW 44 | 45 |
46 | 47 |
48 | 57 |
58 |
59 | 60 | -------------------------------------------------------------------------------- /templates/Includes/ContactUsCustomForm2.ss: -------------------------------------------------------------------------------- 1 |
8 | 13 | 14 |
15 | $displayFormField('FirstName', 'First Name','hideLabel', 'required="required"','mb-3').RAW 16 | 17 | $displayFormField('LastName', 'Last Name','hideLabel', 'required="false"','mb-3').RAW 18 | 19 | $displayFormField('Email', 'Email','hideLabel','type="email" required="required"','mb-3').RAW 20 | 21 | $displayFormField('Phone', 'Phone Number','hideLabel','type="text" ','mb-3').RAW 22 | 23 | $displayFormField('Mobile', 'Mobile Number','hideLabel','type="text" ','mb-3').RAW 24 | 25 | $displayFormField('Company', 'Company Name','hideLabel','type="text" ','mb-3').RAW 26 | 27 | $displayFormField('Website', 'Website','hideLabel','type="text" ','mb-3').RAW 28 | 29 | $displayFormField('Address', 'Address','hideLabel','type="text" ','mb-3').RAW 30 | 31 | $displayFormField('Street', 'Street','hideLabel','type="text" ','mb-3').RAW 32 | 33 | $displayFormField('PostalCode', 'Postal Code','hideLabel','type="text" ','mb-3').RAW 34 | 35 | $displayFormField('City', 'City','hideLabel','type="text" ','mb-3').RAW 36 | 37 | $displayFormField('State', 'State','hideLabel','type="text" ','mb-3').RAW 38 | 39 | $displayFormField('Country', 'Country','hideLabel','type="text" ','mb-3').RAW 40 | 41 | $displayFormField('Subject', 'Subject','hideLabel','type="text" ','mb-3').RAW 42 | 43 | $displayFormField('Message', 'Message','hideLabel','type="textarea" required="required" minlength="6" rows="8" cols="20"','textarea-class w-100').RAW 44 | 45 |
46 | 47 |
48 | 57 |
58 |
59 | 60 | -------------------------------------------------------------------------------- /templates/Includes/ContactUsCustomForm3.ss: -------------------------------------------------------------------------------- 1 |
8 | 13 | 14 |
15 |
16 | $displayFormField('FirstName', 'First Name','showLabel', 'required="required"','mb-3', 'col-md-6').RAW 17 | 18 | $displayFormField('LastName', 'Last Name','showLabel', 'required="false"','mb-3', 'col-md-6').RAW 19 | 20 | $displayFormField('Email', 'Email','showLabel','type="email" required="required"','mb-3', 'col-md-6').RAW 21 | 22 | $displayFormField('Phone', 'Phone Number','showLabel','type="text" ','mb-3', 'col-md-6').RAW 23 | 24 | $displayFormField('Mobile', 'Mobile Number','showLabel','type="text" ','mb-3', 'col-md-6').RAW 25 | 26 | $displayFormField('Company', 'Company Name','showLabel','type="text" ','mb-3', 'col-md-6').RAW 27 | 28 | $displayFormField('Website', 'Website','showLabel','type="text" ','mb-3', 'col-md-6').RAW 29 | 30 | $displayFormField('Address', 'Address','showLabel','type="text" ','mb-3', 'col-md-6').RAW 31 | 32 | $displayFormField('Street', 'Street','showLabel','type="text" ','mb-3', 'col-md-6').RAW 33 | 34 | $displayFormField('PostalCode', 'Postal Code','showLabel','type="text" ','mb-3', 'col-md-6').RAW 35 | 36 | $displayFormField('City', 'City','showLabel','type="text" ','mb-3', 'col-md-6').RAW 37 | 38 | $displayFormField('State', 'State','showLabel','type="text" ','mb-3', 'col-md-6').RAW 39 | 40 | $displayFormField('Country', 'Country','showLabel','type="text" ','mb-3', 'col-md-6').RAW 41 | 42 | $displayFormField('Subject', 'Subject','showLabel','type="text" ','mb-3', 'col-md-6').RAW 43 | 44 |
45 | $displayFormField('Message', 'Message','showLabel','type="textarea" required="required" minlength="6" rows="8" cols="20"','textarea-class w-100', 'col-md-12').RAW 46 |
47 |
48 | 49 |
50 | 59 |
60 |
61 | 62 | -------------------------------------------------------------------------------- /templates/Includes/ContactUsCustomForm4.ss: -------------------------------------------------------------------------------- 1 |
8 | 13 | 14 |
15 |
16 | $displayFormField('FirstName', 'First Name','hideLabel', 'required="required"','mb-3', 'col-md-6').RAW 17 | 18 | $displayFormField('LastName', 'Last Name','hideLabel', 'required="false"','mb-3', 'col-md-6').RAW 19 | 20 | $displayFormField('Email', 'Email','hideLabel','type="email" required="required"','mb-3', 'col-md-6').RAW 21 | 22 | $displayFormField('Phone', 'Phone Number','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 23 | 24 | $displayFormField('Mobile', 'Mobile Number','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 25 | 26 | $displayFormField('Company', 'Company Name','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 27 | 28 | $displayFormField('Website', 'Website','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 29 | 30 | $displayFormField('Address', 'Address','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 31 | 32 | $displayFormField('Street', 'Street','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 33 | 34 | $displayFormField('PostalCode', 'Postal Code','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 35 | 36 | $displayFormField('City', 'City','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 37 | 38 | $displayFormField('State', 'State','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 39 | 40 | $displayFormField('Country', 'Country','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 41 | 42 | $displayFormField('Subject', 'Subject','hideLabel','type="text" ','mb-3', 'col-md-6').RAW 43 | 44 |
45 | $displayFormField('Message', 'Message','hideLabel','type="textarea" required="required" minlength="6" rows="8" cols="20"','textarea-class w-100', 'col-md-12').RAW 46 |
47 |
48 | 49 |
50 | 59 |
60 |
61 | 62 | -------------------------------------------------------------------------------- /src/CustomLayoutPageController.php: -------------------------------------------------------------------------------- 1 | ThemeDir(), '/simple')) { 23 | Requirements::css('https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css'); 24 | } 25 | 26 | } 27 | 28 | public function ErrorMessage() 29 | { 30 | return 'Woops, Something went wrong with the submission. Please contact us or try again later.'; 31 | } 32 | 33 | public function showGoogleRecaptcha() 34 | { 35 | if (!$this->GoogleRecaptchaEnable) { 36 | return ''; 37 | } 38 | $siteKey = $this->GoogleRecaptchaSiteKey; 39 | 40 | if (strlen($siteKey) < 20) { 41 | // check the site_key from mysite.xml 42 | 43 | $config = SiteConfig::current_site_config(); 44 | if ( strlen($config->GoogleRecaptchaSiteKey)>20 ){ 45 | $siteKey = $config->GoogleRecaptchaSiteKey; 46 | } else { 47 | // no site key 48 | return ''; 49 | } 50 | } 51 | return GoogleRecaptcha::show($siteKey, 'ContactUsForm_ContactUsForm_Message', 'no_debug', $this->GoogleRecaptchaCssClass, $this->GoogleRecaptchaNoTickMsg); 52 | } 53 | 54 | function loadCustomTemplate() 55 | { 56 | $str = ''; 57 | $ssFile = trim(str_replace('.ss', '', $this->PageLayoutFilename)); 58 | if ($ssFile != '') { 59 | $str = '' . $this->renderWith('Includes/' . $ssFile); 60 | } 61 | return $str; 62 | } 63 | 64 | function formFieldEnabled($fieldName) { 65 | $ary = explode('|',str_replace(' ','', strtolower($this->DisplayFormFields))); 66 | if ( in_array(strtolower(trim($fieldName)), $ary) ){ 67 | return true; 68 | } 69 | return false; 70 | } 71 | 72 | function displayFormField($fieldName, $labelText = '', $showLabel = 'showLabel', $attributeStr= '', $inputClass= '', $holderClass= '') { 73 | if ( !$this->formFieldEnabled($fieldName) ){ 74 | return ''; 75 | } 76 | if ( $labelText == 'First Name' && !$this->formFieldEnabled('LastName') ){ 77 | $labelText = 'Your Name'; 78 | } 79 | 80 | $labelCss = ( $showLabel == 'showLabel' ) ? 'showLabel' : 'd-none hideLabel'; 81 | $placeholder = ( $showLabel == 'showLabel' ) ? '' : $labelText; 82 | 83 | $fieldHtml = '
84 | 85 |
'; 86 | if ( strpos($attributeStr, 'textarea') ){ 87 | $fieldHtml .= ''; 94 | } else { 95 | $fieldHtml .= ''; 102 | } 103 | 104 | 105 | $fieldHtml .= '
106 |
'; 107 | 108 | return $fieldHtml; 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /src/ContactUs.php: -------------------------------------------------------------------------------- 1 | 'Varchar(255)', 22 | 'LastName' => 'Varchar(255)', 23 | 'CompanyName' => 'Varchar(255)', 24 | 'Email' => 'Varchar(255)', 25 | 'Phone' => 'Varchar(255)', 26 | 'Mobile' => 'Varchar(255)', 27 | 'Street' => 'Varchar(255)', 28 | 'Address' => 'Varchar(255)', 29 | 'PostalCode' => 'Varchar(255)', 30 | 'City' => 'Varchar(255)', 31 | 'State' => 'Varchar(255)', 32 | 'Country' => 'Varchar(255)', 33 | 'Website' => 'Varchar(255)', 34 | 'Locale' => 'Varchar(255)', 35 | 'FromPageTitle' => 'Varchar(255)', 36 | 'Category' => 'Varchar(255)', 37 | 'MyDate' => 'Varchar(255)', 38 | 'IP' => 'Varchar(255)', 39 | 'Subject' => 'Varchar(255)', 40 | 'Message' => 'Text', 41 | 'FromPageUrl' => 'Varchar(255)', 42 | 'AdminComment' => 'Text', 43 | 'Status' => "Enum('New, Opened, Answered, Spam, Archived, Display', 'New')", 44 | 'Sort' => 'Int', 45 | 'ExtraData1' => 'Text', 46 | 'ExtraData2' => 'Text', 47 | 'ExtraData3' => 'Text', 48 | 'ExtraData4' => 'Text', 49 | 'ExtraData5' => 'Text', 50 | ]; 51 | 52 | private static $has_one = []; 53 | 54 | private static $table_name = 'SSC_ContactUs'; 55 | 56 | private static $casting = [ 57 | 'Title' => 'Varchar(255)', 58 | ]; 59 | 60 | private static $defaults = [ 61 | 'Status' => 'New', 62 | ]; 63 | 64 | private static $singular_name = 'Contact Us Data'; 65 | private static $plural_name = 'Contact Us Data'; 66 | private static $default_sort = 'Sort, ID Desc'; 67 | 68 | private static $searchable_fields = [ 69 | 'FirstName', 70 | 'LastName', 71 | 'Email', 72 | 'Phone', 73 | 'Status', 74 | ]; 75 | 76 | private static $summary_fields = [ 77 | 'FullName', 78 | 'Email', 79 | 'Status', 80 | 'FromPageTitle', 81 | 'Created', 82 | ]; 83 | 84 | private static $field_labels = [ 85 | 'FullName' => 'Full Name', 86 | 'Sort' => 'Sort Index', 87 | ]; 88 | 89 | public function getFullName() 90 | { 91 | return $this->FirstName.' '.$this->LastName; 92 | } 93 | 94 | public function FullName() 95 | { 96 | return $this->getFullName(); 97 | } 98 | 99 | public function getTitle() 100 | { 101 | return $this->getFullName().' / '.$this->Status.' / '.$this->Created; 102 | } 103 | 104 | public function Title() 105 | { 106 | return $this->getTitle(); 107 | } 108 | 109 | public static function get_status_options() 110 | { 111 | return singleton(self::class)->dbObject('Status')->enumValues(false); 112 | } 113 | 114 | public function getCMSFields() 115 | { 116 | $fields = FieldList::create(TabSet::create('Root', Tab::create('Main'))); 117 | $fields->removeByName('Sort'); 118 | 119 | $dropFieldStatus = DropdownField::create('Status', 'Status', self::get_status_options()); 120 | 121 | $tabName = singleton(self::class)->singular_name(); 122 | $fields->addFieldsToTab('Root.Main', [ 123 | HeaderField::create('HeaderDetails', "${tabName} details"), 124 | $dropFieldStatus, 125 | TextField::create('FirstName'), 126 | TextField::create('LastName'), 127 | TextField::create('Email', 'Email'), 128 | TextField::create('Phone', 'Phone'), 129 | TextField::create('Mobile', 'Mobile'), 130 | TextField::create('CompanyName', 'Company Name'), 131 | TextField::create('Address', 'Address'), 132 | TextareaField::create('Message', 'Message'), 133 | TextareaField::create('AdminComment', 'Admin Comment'), 134 | ReadOnlyField::create('FromPageTitle'), 135 | ReadOnlyField::create('FromPageUrl', 'From Page URL'), 136 | ReadOnlyField::create('IP', 'Client IP Address'), 137 | ReadOnlyField::create('Locale', 'Locale'), 138 | ReadOnlyField::create('Created', 'Created'), 139 | 140 | 141 | TextField::create('Website'), 142 | TextField::create('PostalCode'), 143 | TextField::create('Street'), 144 | TextField::create('City'), 145 | TextField::create('State'), 146 | TextField::create('Country'), 147 | TextField::create('Category'), 148 | TextField::create('MyDate'), 149 | 150 | TextareaField::create('ExtraData1', 'ExtraData1'), 151 | TextareaField::create('ExtraData2', 'ExtraData2'), 152 | TextareaField::create('ExtraData3', 'ExtraData3'), 153 | TextareaField::create('ExtraData3', 'ExtraData4'), 154 | TextareaField::create('ExtraData3', 'ExtraData5'), 155 | ]); 156 | 157 | return $fields; 158 | } 159 | 160 | } 161 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SilverStripe Custom Layout Page with Contact Us Form & Google Recaptcha 2 | [![Latest Stable Version](https://poser.pugx.org/alexstack/silverstripe-custom-page-with-contact-us-form/v/stable)](https://packagist.org/packages/alexstack/silverstripe-custom-page-with-contact-us-form) 3 | [![License](https://poser.pugx.org/alexstack/silverstripe-custom-page-with-contact-us-form/license)](https://packagist.org/packages/alexstack/silverstripe-custom-page-with-contact-us-form) 4 | [![Total Downloads](https://poser.pugx.org/alexstack/silverstripe-custom-page-with-contact-us-form/downloads)](https://packagist.org/packages/alexstack/silverstripe-custom-page-with-contact-us-form) 5 | 6 | - SilverStripe Custom Layout Page with Contact Us Form & flexible frontend with Google Recaptcha. 7 | 8 | # How to install 9 | 10 | ```php 11 | composer require alexstack/silverstripe-custom-page-with-contact-us-form 12 | ``` 13 | # Rebuild the database and flush admin page 14 | - Run your-site-url/dev/build?flush=1 after composer install and refresh your admin page by /admin?flush=1 15 | 16 | # How to use it 17 | - [x] [Create a new page in SilverStripe admin and choose page type "Custom Page with Contact Us Form"](#choose-page-type) 18 | - [x] [Choose custom page layout](#select-page-layout) from [built-in layouts](#built-in-layouts) 19 | - [x] Or [use your own template xxx.ss](#custom-ss) 20 | - [x] [Change Form Settings ](#form-settings), [Custom form display fields](#display-fields) 21 | - [x] [Set up Google Recaptcha](#set-up-google-recaptcha) 22 | - [x] [Save & publish the page](#publish-page) 23 | 24 | 25 | # Create a new page in SilverStripe admin and choose page type "Custom Page with Contact Us Form" 26 | ![choose page type](docs/images/choose-page-type.png "choose page type") 27 | 28 | # Choose custom page layout 29 | ![Choose custom page layout](docs/images/select-page-layout.png "Choose custom page layout") 30 | 31 | # Change Form Settings 32 | ![Change Form Settings](docs/images/contact-us-form-settings.png "Change Form Settings") 33 | 34 | # Set up Google Recaptcha v2 35 | ![Set up Google Recaptcha v2](docs/images/set-up-google-recaptcha.png "Set up Google Recaptcha v2") 36 | 37 | # Set up Google Recaptcha v3 38 | ![Set up Google Recaptcha v3](docs/images/set-up-google-recaptcha-v3.png "Set up Google Recaptcha v3") 39 | 40 | # Change global settings 41 | ![Change global settings](docs/images/global-settings.png "Change global settings") 42 | 43 | # Built-in page layouts 44 | - It will use your page.ss in your own theme folder for global layout. eg. it will use your own header/footer/css/js 45 | - Built-in page layouts use bootstrap 4.x for grid layout 46 | ### Built-in layout 1: Content Left, Form right if enabled 47 | ![Content Left, Form right if enabled](docs/images/page-layout-001.png "Content Left, Form right if enabled") 48 | ### Built-in layout 2: Content Right, Form left if enabled 49 | ![Content Right, Form left if enabled ](docs/images/page-layout-002.png "Content Right, Form left if enabled ") 50 | ### Built-in layout 3: Content Top, Form bottom if enabled 51 | ![Content Top, Form bottom if enabled ](docs/images/page-layout-003.png "Content Top, Form bottom if enabled ") 52 | ### Built-in layout 4: Content Top, 3 cards below with Extra Images 1,2,3 53 | ![Content Top, 3 cards below with Extra Images 1,2,3 ](docs/images/page-layout-004.png "Content Top, 3 cards below with Extra Images 1,2,3 ") 54 | ### Built-in layout 5: Two Contents per line, two lines with Extra Content 1,2,3 55 | ![2 Contents per line, 2 lines with Extra Content 1,2,3 ](docs/images/page-layout-005.png "2 Contents per line, 2 lines with Extra Content 1,2,3 ") 56 | 57 | # Use your own .ss template file for a custom page layout 58 | - eg. NewProductPage.ss. Please make sure the template file your-theme/templates/includes/xxx.ss already exists! 59 | - How to start the .ss: Copy vendor/alexstack/silverstripe-custom-page-with-contact-us-form/templates/Includes/CustomLayoutPage1.ss to your-theme/includes, rename it to NewProductPage.ss, change the .ss code inside to what you want. Just keep the variable names the same. 60 | ![custom-my-own-template-file](docs/images/custom-my-own-template-file.png) 61 | - Do not forget to run ?flush=1 first to load your new .ss template 62 | 63 | # Contact Us Form display fields 64 | - There are some built-in fields. You can choose what fields will display from FirstName | Email | Phone | Message | LastName | Mobile | Company | Website | Address | Street | PostalCode | City | State | Country 65 | - Use | for the fields separator. 66 | - By default, the form will display: FirstName | Email | Phone | Company | Message 67 | - You can easily change Company to Address by replace it with: FirstName | Email | Phone | Company | Message 68 | - Or you can add more fields if you want. 69 | 70 | # Override the frontend form template 71 | - You can override the .ss template file if you want to add more fields or change fields display orders, or something else. 72 | - How to override: Copy vendor/alexstack/silverstripe-custom-page-with-contact-us-form/templates/Includes/ContactUsCustomForm1.ss to your-theme/includes, and add/change the html inside to what you want. Just keep the input field name the same. 73 | - Can I add more fields to the form? You can also add some extra fields to extend the form without touch a php file or database. Available extra field names are: ExtraData1, ExtraData2, ExtraData3, ExtraData4, ExtraData5, Category, MyDate 74 | - Override a form .ss template example screenshot: 75 | ![override-form-ss](docs/images/override-form-ss.png) 76 | 77 | # View contact us form data 78 | - It will send an email to the notification email address after a form submitted 79 | - And you can view all the data in admin: 80 | ![view-contact-us-data](docs/images/view-contact-us-data.png) 81 | 82 | # Thanks 83 | - Inspired by Fractaslabs' contact-page 84 | 85 | # License 86 | - BSD-3-Clause -------------------------------------------------------------------------------- /src/CustomLayoutPage.php: -------------------------------------------------------------------------------- 1 | 'Varchar(255)', 30 | 'PageLayout' => 'Varchar(255)', 31 | 'PageLayoutFilename' => 'Varchar(255)', 32 | 'FormLayoutFilename' => 'Varchar(255)', 33 | 'DisplayFormFields' => 'Text', 34 | 'MailFrom' => 'Varchar(255)', 35 | 'MailTo' => 'Varchar(255)', 36 | 'MailSubject' => 'Varchar(255)', 37 | 'SuccessTitle' => 'Varchar(255)', 38 | 'SuccessText' => 'HTMLText', 39 | 'GoogleRecaptchaSiteKey' => 'Text', 40 | 'GoogleRecaptchaSecretKey' => 'Text', 41 | 'GoogleRecaptchaCssClass' => 'Varchar(255)', 42 | 'GoogleRecaptchaNoTickMsg' => 'Varchar(255)', 43 | 'GoogleRecaptchaEnable' => DBBoolean::class, 44 | 'FormEnable' => DBBoolean::class, 45 | 'ExtraContent1' => 'HTMLText', 46 | 'ExtraContent2' => 'HTMLText', 47 | 'ExtraContent3' => 'HTMLText', 48 | 'ExtraText1' => 'Text', 49 | 'ExtraText2' => 'Text', 50 | 'ExtraText3' => 'Text', 51 | 'ExtraFeaturedText' => 'Text', 52 | 'ExtraFeaturedContent' => 'HTMLText', 53 | ]; 54 | 55 | private static $has_one = [ 56 | 'ExtraImage1' => Image::class, 57 | 'ExtraImage2' => Image::class, 58 | 'ExtraImage3' => Image::class, 59 | 'ExtraFile1' => File::class, 60 | 'ExtraFile2' => File::class, 61 | 'ExtraFile3' => File::class, 62 | 'ExtraFeaturedImage' => Image::class, 63 | ]; 64 | 65 | private static $table_name = 'SSC_CustomLayoutPage'; 66 | 67 | private static $owns = ['ExtraImage1', 'ExtraImage2', 'ExtraImage3', 'ExtraFile1', 'ExtraFile2', 'ExtraFile3']; 68 | 69 | private static $default_sort = 'ID DESC'; 70 | 71 | private static $defaults = [ 72 | 'FormEnable' => true, 73 | 'FormLayout' => '1', 74 | 'PageLayout' => '1', 75 | 'MailFrom' => '', 76 | 'MailTo' => '', 77 | 'MailSubject' => 'New contact us form inquiry', 78 | 'SuccessTitle' => 'Thank You', 79 | 'DisplayFormFields' => 'FirstName | Email | Phone | Company | Message', 80 | 'SuccessText' => '

Thank you for submitting the contact form!

We will get back to you ASAP.

', 81 | 'GoogleRecaptchaCssClass' => 'mt-3 mb-3', 82 | 'GoogleRecaptchaNoTickMsg' => 'Please tick the I\'m not a robot checkbox first!' 83 | ]; 84 | 85 | 86 | public function getCMSFields() 87 | { 88 | $fields = parent::getCMSFields(); 89 | $pageLayoutSourceAry = array( 90 | "1" => "Content Left, Form right if enabled", 91 | "2" => "Content Right, Form left if enabled", 92 | "3" => "Content Top, Form bottom if enabled", 93 | "4" => "Content Top, 3 cards below with Extra Images 1,2,3", 94 | "5" => "Two Contents per line, two lines with Extra Content 1,2,3", 95 | "101" => "My Custom Template File xxx.ss", 96 | ); 97 | 98 | $fields->addFieldsToTab('Root.ExtraContent', [ 99 | TextField::create('ExtraFeaturedText', 'Extra Featured Text'), 100 | TextField::create('ExtraText1', 'Extra Text 1'), 101 | TextField::create('ExtraText2', 'Extra Text 2'), 102 | TextField::create('ExtraText3', 'Extra Text 3'), 103 | UploadField::create('ExtraFeaturedImage', 'Extra Featured Image'), 104 | UploadField::create('ExtraImage1', 'Extra Image 1'), 105 | UploadField::create('ExtraImage2', 'Extra Image 2'), 106 | UploadField::create('ExtraImage3', 'Extra Image 3'), 107 | HtmlEditorField::create('ExtraFeaturedContent', 'Extra Featured Content'), 108 | HtmlEditorField::create('ExtraContent1', 'Extra Content 1'), 109 | HtmlEditorField::create('ExtraContent2', 'Extra Content 2'), 110 | HtmlEditorField::create('ExtraContent3', 'Extra Content 3'), 111 | 112 | UploadField::create('ExtraFile1', 'Extra File 1'), 113 | UploadField::create('ExtraFile2', 'Extra File 2'), 114 | UploadField::create('ExtraFile3', 'Extra File 3'), 115 | 116 | ]); 117 | $fields->addFieldsToTab('Root.PageLayout', [ 118 | $pageLayout = new OptionsetField("PageLayout", "Page Layout", $pageLayoutSourceAry, $value = "1"), 119 | TextField::create('PageLayoutFilename', 'Custom Template File') 120 | ->setDescription("eg. NewProductPage.ss. Please make sure the template file your-theme/templates/includes/xxx.ss already exists!"), 121 | ]); 122 | $pageLayout->addExtraClass('PageLayoutOptions')->setDescription("

" . $pageLayoutSourceAry[$this->PageLayout] . "

123 | "); 135 | 136 | $fields->addFieldsToTab('Root.FormSettings', [ 137 | CheckboxField::create('FormEnable', 'Enable Contact Us Form')->setDescription(''), 138 | new DropdownField('FormLayout', 'Form Layout', [ 139 | '1' => 'Vertical with label', 140 | '2' => 'Vertical without label', 141 | '3' => 'Horizontal with label', 142 | '4' => 'Horizontal without label', 143 | '5' => 'System Generated - For Dev Test', 144 | ]), 145 | 146 | TextField::create('DisplayFormFields', 'Display Fields')->setDescription('You can choose what fields will display from FirstName | Email | Phone | Message | LastName | Mobile | Company | Website | Address | Street | PostalCode | City | State | Country. Document is here. '), 147 | TextField::create('MailTo', 'Notify Email')->setDescription('This person will get notification after someone submit the form. Will get the value from the global settings if it is empty.'), 148 | TextField::create('MailSubject', 'Mail Subject') 149 | ->setDescription('We will not send email if this Mail Subject is empty'), 150 | 151 | TextField::create('SuccessTitle', 'Success Title') 152 | ->setDescription('This will display as a title after the form success submitted.'), 153 | HTMLEditorField::create('SuccessText', 'Success Text') 154 | ->setDescription('This will display as a content after the form success submitted.You can put links or images here.'), 155 | ]); 156 | 157 | 158 | $fields->addFieldsToTab('Root.GoogleRecaptcha', [ 159 | CheckboxField::create('GoogleRecaptchaEnable', 'Enable Google Recaptcha')->setDescription(''), 160 | 161 | TextField::create('GoogleRecaptchaCssClass', 'Recaptcha Css Class')->setDescription('Extra css class name for the Google Recaptcha area. eg. mt-4 show-inline-badge mb-5
GoogleRecaptcha v3: Add a string show-inline-badge will display a badge instead of float at right bottom'), 162 | 163 | TextField::create('GoogleRecaptchaNoTickMsg', 'Recaptcha No Tick Msg')->setDescription('GoogleRecaptcha v2: Frontend alert message if not tick the I\'m not a robot checkbox.
GoogleRecaptcha v3: Change the value to v3 will use GoogleRecaptcha v3 instead of v2'), 164 | 165 | TextField::create('GoogleRecaptchaSiteKey', 'Recaptcha Site Key')->setDescription('Will get the Site Key from the global settings if it is empty'), 166 | TextField::create('GoogleRecaptchaSecretKey', 'Recaptcha Secret Key')->setDescription('Will get the Secret Key from the global settings if it is empty'), 167 | 168 | ]); 169 | 170 | return $fields; 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/ContactUsForm.php: -------------------------------------------------------------------------------- 1 | currentController = $controller; 29 | 30 | $fields = FieldList::create( 31 | [ 32 | TextField::create('FirstName') 33 | ->setTitle('First Name') 34 | ->setAttribute('required', 'required') 35 | ->setAttribute('class', 'form-control') 36 | , 37 | 38 | TextField::create('LastName') 39 | ->setTitle('Last Name') 40 | ->setAttribute('class', 'form-control') 41 | , 42 | 43 | EmailField::create('Email') 44 | ->setTitle('Email') 45 | ->setAttribute('type', 'email') 46 | ->setAttribute('class', 'form-control') 47 | ->setAttribute('required', 'required') 48 | , 49 | 50 | TextField::create('Phone') 51 | ->setTitle('Phone') 52 | ->setAttribute('class', 'form-control') 53 | , 54 | TextField::create('Mobile') 55 | ->setAttribute('class', 'form-control') 56 | , 57 | 58 | TextField::create('CompanyName') 59 | ->setTitle('Company Name') 60 | ->setAttribute('class', 'form-control') 61 | , 62 | TextField::create('Website') 63 | ->setAttribute('class', 'form-control'), 64 | 65 | 66 | TextField::create('Address') 67 | ->setTitle('Address') 68 | ->setAttribute('placeholder', '')->setAttribute('class', 'form-control'), 69 | 70 | TextField::create('Street') 71 | ->setAttribute('class', 'form-control') 72 | , 73 | TextField::create('PostalCode') 74 | ->setAttribute('class', 'form-control') 75 | , 76 | TextField::create('City') 77 | ->setAttribute('class', 'form-control') 78 | , 79 | TextField::create('State') 80 | ->setAttribute('class', 'form-control') 81 | , 82 | TextField::create('Country') 83 | ->setAttribute('class', 'form-control') 84 | , 85 | TextField::create('Subject') 86 | ->setAttribute('class', 'form-control') 87 | , 88 | TextareaField::create('Message') 89 | ->setTitle('Message') 90 | ->setRows(8)->setAttribute('class', 'form-control') 91 | ->setAttribute('required', 'required') 92 | ->setAttribute('minlength', '6'), 93 | 94 | 95 | HiddenField::create('ExtraData1'), 96 | HiddenField::create('ExtraData2'), 97 | HiddenField::create('ExtraData3'), 98 | HiddenField::create('ExtraData4'), 99 | HiddenField::create('ExtraData5'), 100 | HiddenField::create('Category'), 101 | HiddenField::create('MyDate'), 102 | 103 | ] 104 | ); 105 | 106 | $actions = FieldList::create( 107 | FormAction::create('SaveFormData', 'Submit')->setUseButtonTag(true)->setAttribute('class', 'btn btn-primary mt-2 btn-submit') 108 | ); 109 | 110 | $validator = RequiredFields::create('FirstName'); 111 | 112 | parent::__construct($controller, $name, $fields, $actions, $validator); 113 | 114 | $this->disableSecurityToken(); 115 | 116 | if (null !== $this->extend('updateFields', $fields)) { 117 | $this->setFields($fields); 118 | } 119 | if (null !== $this->extend('updateActions', $actions)) { 120 | $this->setActions($actions); 121 | } 122 | 123 | $session = $this->currentController->getRequest()->getSession(); 124 | $oldData = $session->get("FormInfo.{$this->FormName()}.data"); 125 | if ($oldData && (is_array($oldData) || is_object($oldData))) { 126 | $this->loadDataFrom($oldData); 127 | } 128 | $this->extend('updateContactUsForm', $this); 129 | } 130 | 131 | /** 132 | * Form action handler for ContactUsForm. 133 | * 134 | * @param array $data The form request data submitted 135 | * @param Form $form The {@link Form} this was submitted on 136 | */ 137 | public function SaveFormData(array $data, Form $form, HTTPRequest $request) 138 | { 139 | $data['FromPageUrl'] = $this->currentController->AbsoluteLink(); 140 | $data['FromPageTitle'] = $this->currentController->Title; 141 | 142 | $raw2sqlData = Convert::raw2sql($data); 143 | $config = SiteConfig::current_site_config(); 144 | 145 | if ( $this->currentController->GoogleRecaptchaEnable ){ 146 | $secretKey = $this->currentController->GoogleRecaptchaSecretKey; 147 | 148 | if ( strlen($secretKey) < 20 ){ 149 | $secretKey = $config->GoogleRecaptchaSecretKey; 150 | } 151 | 152 | 153 | GoogleRecaptcha::verify($secretKey, 'Google Recaptcha Validation Failed!!'); 154 | } 155 | 156 | $item = ContactUs::create(); 157 | 158 | $item->FromPageTitle = $data['FromPageTitle']; 159 | $item->FromPageUrl = $data['FromPageUrl']; 160 | $item->IP = $this->getClientIP(); 161 | $form->saveInto($item); 162 | $item->write(); 163 | 164 | 165 | 166 | /** 167 | * Send Email notification to site administrator or 168 | * to email specified in MailTo field. 169 | */ 170 | $email_sent = true; //? 171 | $mailFrom = $raw2sqlData['Email']; 172 | $mailTo = $this->currentController->MailTo ? $this->currentController->MailTo : $config->ContactUsEmail; 173 | 174 | try{ 175 | if ( strpos($mailFrom, '@') && strpos($mailTo, '@') ){ 176 | 177 | $mailSubject = $this->currentController->MailSubject ? 178 | ($this->currentController->MailSubject . ' from ' . $config->Title) : 179 | 'no-subject'; 180 | $email = Email::create($mailFrom, $mailTo, $mailSubject); 181 | $email->setReplyTo($raw2sqlData['Email']); 182 | $email->setHTMLTemplate('SSCustomPageWithContactUsForm\\Email\\ContactUsEmail'); 183 | $email->setData($raw2sqlData); 184 | $email_sent = $email->send(); 185 | 186 | // maybe send the user an email as well 187 | 188 | } 189 | } 190 | catch(Exception $e) { 191 | $email_sent = false; 192 | } 193 | 194 | 195 | 196 | /* 197 | * Handle validation messages 198 | * Error message is presented on ContactUsPage.ss layout as 199 | * a variable $ErrorMessage 200 | */ 201 | if ($email_sent) { 202 | $this->currentController->redirect($this->currentController->Link().'success'); 203 | } else { 204 | $this->currentController->redirect($this->currentController->Link().'error'); 205 | } 206 | 207 | return false; 208 | } 209 | 210 | /** 211 | * saves the form into session. 212 | * 213 | * @param array $data - data from form 214 | */ 215 | public function saveDataToSession() 216 | { 217 | $data = $this->getData(); 218 | $session = $this->currentController->getRequest()->getSession(); 219 | $session->set("FormInfo.{$this->FormName()}.data", $data); 220 | } 221 | 222 | // Function to get the client IP address 223 | function getClientIP() { 224 | $ipaddress = ''; 225 | if (isset($_SERVER['HTTP_CLIENT_IP'])) 226 | $ipaddress = $_SERVER['HTTP_CLIENT_IP']; 227 | else if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) 228 | $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR']; 229 | else if(isset($_SERVER['HTTP_X_FORWARDED'])) 230 | $ipaddress = $_SERVER['HTTP_X_FORWARDED']; 231 | else if(isset($_SERVER['HTTP_FORWARDED_FOR'])) 232 | $ipaddress = $_SERVER['HTTP_FORWARDED_FOR']; 233 | else if(isset($_SERVER['HTTP_FORWARDED'])) 234 | $ipaddress = $_SERVER['HTTP_FORWARDED']; 235 | else if(isset($_SERVER['REMOTE_ADDR'])) 236 | $ipaddress = $_SERVER['REMOTE_ADDR']; 237 | else 238 | $ipaddress = 'UNKNOWN'; 239 | return $ipaddress; 240 | } 241 | } 242 | 243 | 244 | 245 | class ContactUsForm_Validator extends RequiredFields 246 | { 247 | public function php($data) 248 | { 249 | $this->form->saveDataToSession(); 250 | 251 | return parent::validate($data); 252 | } 253 | } 254 | -------------------------------------------------------------------------------- /templates/SSCustomPageWithContactUsForm/Email/ContactUsEmail.ss: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | $MailSubject 10 | 11 | 16 | 17 | 18 | 19 |
20 |
21 |
22 |

Full Name:

23 |
24 |
25 | $FirstName $LastName 26 |
27 |
28 | 29 |
30 |
31 |

Email:

32 |
33 |
34 | $Email 35 |
36 |
37 | 38 |
39 |
40 |

Phone:

41 |
42 |
43 | $Phone 44 |
45 |
46 | 47 |
48 |
49 |

Address:

50 |
51 |
52 | $Address 53 |
54 |
55 |
56 |
57 |

Message:

58 |
59 |
60 | $Message 61 |
62 |
63 | 64 |
65 |
66 |

From Page:

67 |
68 |
69 | $FromPageUrl 70 |
71 |
72 | 73 |
74 |
75 |

More Details:

76 |
77 |
78 | Please log into the website admin for more details. 79 |
80 |
81 |
82 | 83 | 84 | 85 | 86 | --------------------------------------------------------------------------------