How to get the form block to send email to form submitter

Permalink
So after much searching, reading and gnashing of teeth, I finally figured out how to make the built-in form block send a confirmation email to site visitors who fill out the form. Not being a php guy and being on a shoestring budget (i.e. no paid blocks, sorry) made this more time-consuming than I would have preferred but it works now.

First, I copied the core form block folder (root/concrete/blocks/form) to the root blocks folder (root/blocks/form).

Next i edited the controller.php file in root/blocks/form. I added a block of code around line 340 above the code that sends an email to the address entered in the block itself. Here's the code:
$mh = Loader::helper('mail');
            $mh->to( $questionAnswerPairs[9]['answer'] );
            $mh->from( $formFormEmailAddress );
            $mh->addParameter('formName', $this->surveyName);
            $mh->addParameter('questionSetId', $this->questionSetId);
            $mh->addParameter('questionAnswerPairs', $questionAnswerPairs);
            $mh->load('block_form_submission_user');
            $mh->setSubject(t('%s Form Submission', $this->surveyName));
            //echo $mh->body.'<br>';
            $mh->sendMail();

This line:
$mh->to( $questionAnswerPairs[9]['answer'] );
tells the block to send an email to whatever is entered in question/answer pair#9. This line will be different depending on which field is used for email. The first field in a form is field "0". each subsequent field is 1, 2, 3, etc. The email field on my form was the tenth field hence
$questionAnswerPairs[9]['answer']
.

I wanted to format the email the submitter receives differently from the one I receive. The form block uses a file called block_form_submission.php (found in the core/mail folder) to format form submission emails. I copied this file to the root/mail folder and changed it to my liking. Next I copied it to another file and named it block_form_submission_user.php, this is the file used to format the email that the form submitter receives. This line from the code above tells the block to use this alternate file:
$mh->load('block_form_submission_user');


That's pretty much it. I'm sure there are more elegant ways to accomplish this and yes, i could have just purchased a block that would do all this and more. BUT, I typically learn by doing and this has taught me alot about C5. Also I'm cheap. Sue me. As I learn more about php, i will be able to a better job. In the mean time, I'm just glad it works.

Hope this helps somebody out there with the same questions I had.

brothersjef
 
12345j replied on at Permalink Reply
12345j
brothersjef replied on at Permalink Reply
brothersjef
Does this controller send an email to the submitter? It seems to use the user_email as the from address. Looks like it also allows you to add a couple additional field types including "email" which is VERY cool.
nickratering replied on at Permalink Reply
nickratering
Does this work for 5.6.0.2?
I get many requests for this feature!
R4YM3 replied on at Permalink Reply
R4YM3
Bump
R4YM3 replied on at Permalink Reply
R4YM3
It does
webmaster55 replied on at Permalink Reply
Hello. I'm running Concrete5 version 5.6.2.1. There seems to have been a recent update which changed the server file structure significantly. I'm looking for the controller.php mentioned above. Several months ago I edited the controller.php in a similar way brothersjef did, and things worked perfectly. However, my file structure has recently changed when installing a newer version, and the controller.php file in my root/concrete/blocks/form folder now is clearly not the same as the one above. Mine has only a few lines. Here it is in its entirety:
<?php  
defined('C5_EXECUTE') or die("Access Denied.");
class FormBlockController extends Concrete5_Controller_Block_Form {}
class FormBlockStatistics extends Concrete5_Controller_Block_FormStatistics {}
class MiniSurvey extends Concrete5_Controller_Block_FormMinisurvey {}

I'm not exactly sure what the code here does, but it looks like it extends some base classes. Where can I find these base class files? Any help on finding the equivalent controller.php file that brothersjef edited will be appreciated. Thank you.
webmaster55 replied on at Permalink Reply
Never mind, I found it. If anyone else has the same problem, the file I was looking for is at /concrete/core/controllers/blocks/form.php.