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

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->setSubject(t('%s Form Submission', $this->surveyName));
            //echo $mh->body.'<br>';

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

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:

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.

View Replies:
12345j replied on at Permalink Reply
brothersjef replied on at Permalink Reply
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
Does this work for
I get many requests for this feature!
R4YM3 replied on at Permalink Reply
R4YM3 replied on at Permalink Reply
It does
webmaster55 replied on at Permalink Reply
Hello. I'm running Concrete5 version 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:
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.