justb3a

Simple Contact Form

224 posts in this topic

Just a simple contact form including spam protection.
Optional support for Twig (TemplateTwigReplace) as template engine.
 
---
 
Please have a look at the readme on github!
If you upgrade from version 0.0.9 and below, there are some extra steps to be taken.

The Guides

Edited by justb3a
Added the "module" tag and removed it from title.
26 people like this

Share this post


Link to post
Share on other sites

This is great. I thought about doing a contact form module myself as i would have needed it in nearly every single project we've done recently.

Btw: I like that all of your modules support TemplateTwigReplace! :)

Share this post


Link to post
Share on other sites

Amazing!

I've been mostly doing this functionality in my templates as far as I haven't needed any save functionality but I will be defiantly be checking this out when i do.

Share this post


Link to post
Share on other sites

Little update: I added one more spam protection:

  • antiSpamCountAdditionalInputs - Number of additional inputs. Spam bots often send more than the number of available fields.

Thanks for your feedback  :)

Share this post


Link to post
Share on other sites

Very nice.. just tryed it out and works perfectly.

I had a little trouble with ajax but sorted out in the end.

My fault for copy and pasting from the instructions but this code below needs to be changed:

if ($('.js-simplecontactform').length) {
  $.simplecontactform($('.js-simplecontactform'));
}

to

if ($('.js-simple_contact_form').length) {
   $.simplecontactform($('.js-simple_contact_form'));
}

just a matter of class name if using the default class of the form in simple_contact_form.php

2 people like this

Share this post


Link to post
Share on other sites

@dazzyweb thanks for pointing that out! I wanted to answer your message but you solved it too fast  :)

Share this post


Link to post
Share on other sites

Hello, 

I was glad to find this module, cause that was just what I looked for.. but I upload the module and when I Install it, I have an error : Method Modules::getInstall does not exist or is not callable in this context

But If I go back in the module page, It seems well installed (I have access to the settings), but when I call the form in my template, an error appears : Error Exception: Method Modules::getInstall does not exist or is not callable in this context (in /home/www/d7a3bc5db5bed31cde906ac7976f3d83/web/wire/core/Wire.php line 231)

Any ideas ? Maybe I skipped a step...

I'm not a Master in PW, but I globally understand how it works..

Thanks in advance.

Share this post


Link to post
Share on other sites

Hi @nyo08,

which version of ProcessWire are you using?

I found a similar error and changed my code as explained.

Please clone the module (github) and checkout  hotfix/2.4-dependency and try again. And please let me know if everything works as expected.

I tested it (ProcessWire 2.5.3) without any problems.

git clone git@github.com:justonestep/processwire-simplecontactform.git SimpleContactForm
cd SimpleContactForm
git checkout  hotfix/2.4-dependency

Share this post


Link to post
Share on other sites

Hi @nyo08,

which version of ProcessWire are you using?

I found a similar error and changed my code as explained.

Please clone the module (github) and checkout  hotfix/2.4-dependency and try again. And please let me know if everything works as expected.

I tested it (ProcessWire 2.5.3) without any problems.

git clone git@github.com:justonestep/processwire-simplecontactform.git SimpleContactForm
cd SimpleContactForm
git checkout  hotfix/2.4-dependency

Indeed I update my PW (I had the 2.2.4 version... looks like I miss some update ahah) and that's perfecly work

O0

Share this post


Link to post
Share on other sites

It would be great if the wireMail function could be used for sending emails instead of the php mail function.

This way people would be able to use it together with their favourite mail extensions. For example with SMTP support: wiremail-swiftmailer or wiremailsmtp

5 people like this

Share this post


Link to post
Share on other sites

@makari: This module creates a simple template, you can / should change the html structure as well as the label texts. If you need multi language support you have to change the text like this echo __("the label text here!"). Now you can translate the labels via Processwire Backend.

@horst: Thats a good point but first I have to finish another project. I will keep it in mind – as some other things (I did not forget your message  ;) ).

2 people like this

Share this post


Link to post
Share on other sites

Hey there,

I've installed this module. It has created a new template simple_contact_form.php

I've created a page and used simple_contact_form.php as its template

So I see the contact form on the new page, but it doesn't seem to work (I've used my @gmail.com as emailTo)

is there anything else I should do to make it work?

Share this post


Link to post
Share on other sites
but it doesn't seem to work (I've used my @gmail.com as emailTo)

Gmail doesn't allow you to send an email from yourself to yourself, unlike other email platforms.  The message gets sent but you don't receive the copy, since if's from yourself.

Share this post


Link to post
Share on other sites

I didn't try to send an e-mail to myself?

I have sent @gmail e-mail in the module settings and was testing it on the site using another e-mail, but nothing much happens there..

Share this post


Link to post
Share on other sites

Ok, then I would then look at the php mail function on your server.  I believe this module doesn't make use of enhanced PW capabilities for email sending.

It would be great if the wireMail function could be used for sending emails instead of the php mail function.
 
This way people would be able to use it together with their favourite mail extensions. For example with SMTP support: wiremail-swiftmailer or wiremailsmtp

Share this post


Link to post
Share on other sites

The module uses now the WireMail function instead of php mail.

Besides I added the tag "scf" for fields and templates created by this module (just available on a new installation).

5 people like this

Share this post


Link to post
Share on other sites

Hi,

Just experienced a couple of bugs with this module which happen when the save messages setting is off.

SimpleContactForm.module

First bug:

if (!$this->pages->findOne('name=' . $this->pageName) instanceof Pages) {

I believe this should be without the "!" at the start as it is currently the wrong way around. Removing it fixed it for me.

Next bug:

} elseif (!in_array($currentIp, $excludeIps)) {

This line should also check if the saveMessages setting is on, i.e.:

} elseif (!in_array($currentIp, $excludeIps) && $this->saveMessages) {

I haven't tested any of these with other settings and I'm not sure they are correct - just needs some looking into.

1 person likes this

Share this post


Link to post
Share on other sites

@pwired:

@makari: This module creates a simple template, you can / should change the html structure as well as the label texts. If you need multi language support you have to change the text like this echo __("the label text here!"). Now you can translate the labels via Processwire Backend.

@BrettMW: Indeed, I only tested this at the beginning with save message settings deactivated. Thanks for your feedback, I will test and implement this as soon as possible. 

Share this post


Link to post
Share on other sites

New version 0.0.9 includes fixes for deactivated save message setting.

On line :343 I removed the exclamation mark (!) and I corrected the instance to compare with. This has to be Page instead of Pages because findOne returns a single page (because of this double bug the messages has been stored). I included a second check here just to make sure that save messages is on. I also included this additional check on line :396. 

3 people like this

Share this post


Link to post
Share on other sites

New version 0.1.0 adds some more spam protection possibilities and logging.

  • CSRF validation
  • mark messages as spam (by mail or/and ip address)
  • logging for received messages and spam
  • sort option for repeater items in backend to get the latest to the beginning of the list

For more information have a look at the readme.

NOTICE: If you upgrade an existing installation from 0.0.9 and below to the current version, there are some steps to be taken.

4 people like this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By bernhard
      Hi,
      just stumbled over a little module that i built for my last project. it helped me to test performance of my rockdatatables module to generate 3000 random json datasets and i want to share it with you. maybe it saves some time for someone.
      https://gitlab.com/baumrock/RockDummyData/
      easy example:
      $rdd = $modules->get('RockDummyData'); for($i=0; $i<15; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); echo date("d.m.Y H:i:s", $dummy->timestamp) . "<br>"; } more advanced:
      $json = new stdClass(); $json->data = array(); $rdd = $modules->get('RockDummyData'); for($i=0; $i<3000; $i++) { // this has to be inside the for-loop to always get a new dummy $dummy = $rdd->getDummy(); $obj = new stdClass(); $obj->name = $dummy->forename . ' ' . $dummy->surname; $obj->position = $dummy->job; $obj->office = $dummy->city; $obj->color = $dummy->color; $obj->start_date = new stdClass(); $obj->start_date->display = date('d.m.Y',$dummy->timestamp); $obj->start_date->sort = $dummy->timestamp; $obj->salary = rand(0,10000); $json->data[] = $obj; } echo json_encode($json); you have to store your random datasets on your own into the /data folder. there are several services for creating all kinds of random data on the web - if you know one service that allows sharing those datasets let me know and i can include common needed data into the module
    • By AndySh
      Hello!
      I need your assistance please. I purchased the module FormBuilder. Unfortunately, the module discontinued delivering customer submissions to e-mail box specified in the module settings. Direct mailing to the e-mail box works OK. The module settings stays the same and are correct, like "Send e-mail to administrator(s) is checked. The last version of FormBuilder 3.0 has been installed. Please advise how to resolve the issue becase I cannot get orders from customers anymore (((
    • By kixe
      As described in this post (https://processwire.com/talk/topic/8551-custom-urls-for-pages/?p=82742) the option 'Name Format Children' under the tab 'Family' in template settings doesn't work properly and also not as expected. I had a look inside the code and made some changes which are working properly, which offers much more options, more consistency and less code too.

      The result is the following. You have 3 Options for generating name and title, which could be combined in endless variations.
      Name is always derived from title, same like creating pages manually.
      type date: if function detects # character anywhere in the string, conversion will be: deletion of # and string will be used as format parameter for PHP date() function type field: if string is a fieldname of the parent page the value of this field will be used type string: if string doesn't fit to the 2 preceeding it will be taken as it is All parts (separated by comma) will be composed in the order of setting. You can use unlimited numbers of parts

      I made a pull request on github: https://github.com/ryancramerdesign/ProcessWire/pull/831

      Example screenshots

      Setting ...


      will result in


       
    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
       
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend