External form or hard coded form block?

Hey guys!
I need to include a form in a page type, which has the some basic functionality as the c5 form block: it can send email messages when the form is submitted and the submissions are tracked in the C5 report system. The email messages must have a subject that is different, depending on the page the form was submitted from. I have no clue on how to start implementing such forms. I would be very happy if someone could give me some help on this. Thanks!

View Replies:
mckoenig replied on at Permalink Reply
A simple hack would be to name the forms differently and then edit the form controller to check for the form name and set up the mail helper accordingly. In the form/controller.php (don't forget to copy it to the root/blocks/ directory first!) at around line 340 you could add something like this:

      case: "form1":         
         $mh->to( '[email protected]' ); 
         $mh->from( '[email protected]' );
        case: "form2":

Of course you need to modify this code to what you need. But the idea is simple, just switch through the form name and act accordingly.

Not exactly the MOST elegant way but works pretty well for me ;)
szucslaszlo replied on at Permalink Reply
Hey there!
Thank you for your efforts! Unfortunatelly, this is exactly what I want to bypass, because there are at least 30 pages plus translations in three languages. :/
I started studying the form controller, specifically the action_form_submit (or something like that) method and I noticed, that might be code I need to copy and modify to suit my needs, but I am somewhat overwhelmed by it -- it seems way too much for such an easy task. :(
Steevb replied on at Permalink Reply
Go to the 'Options tab' when you create your form and give the form a name. That will be the subject line of the email.
Steevb replied on at Permalink Reply
Also forgot to mention a great addon...


...One my favourites
szucslaszlo replied on at Permalink Reply
Unfortunatelly this addon does not suit my needs perfectly. I do not want to create different forms for all the pages (something like 30 pages per language for four langauges). I would like to hard code one form, that would integrate well into C5, that is, the user submissions are tracked just like in the case of the normal form block, plus it sends an email message to the specified email adresses AND to the submitter also. Unfortunatelly I have no idea how to set up a form block manually from code. I don't know if I am clear enough - I am trying to do something similar, when you hard code a navigation into a page with BlockType::getByHandle("autonav")...
jordanlev replied on at Permalink Reply
Do you need the form to have customizable fields (like the built-in form block does)? Or is it okay if you "hard-code" the fields into the form and not have them modifiable by the people managing the site content?
szucslaszlo replied on at Permalink Reply
The form does not need to be editable by C5 users, I hard code it.
jordanlev replied on at Permalink Reply 1 Attachment
Attached is a block with some boilerplate code in it that I use for these kinds of blocks. Here's how to set it up:

1. Unzip and move the "custom_contact_form" folder to your site's top-level "blocks" directory (note: this is just a block, *not* a package -- so don't put it in your "packages" directory).

2. Rename the "custom_contact_form" folder as desired (should be the lowercase_and_underscore version of your block's name -- for example, "My Great Form" would get a directory name of "my_great_form").

3. Edit the block's "controller.php" file:
* Change the class name to be a TitleCaseWithNoSpaces version of the block name (otherwise known as CamelCase), followed by "BlockController" -- for example, "My Great Form" would get a class name of "MyGreatFormBlockController".
* Change the block name and description. It is recommended that the name correspond with the directory and class names, but this is not a technical requirement (just avoids confusion).
* Change the table name to "bt" followed by the CamelCase version of the block name -- for example, "My Great Form" would get a table name of "btMyGreatForm".

4. Edit "db.xml" file so the table name matches what you set in "controller.php".

5. Customize the form as needed. The view.php file contains the form html. The action_submit_form() method in controller.php responds to form submissions.

Good luck!

szucslaszlo replied on at Permalink Reply
Hey there!
I'll give some feedback, when I gave it a try. This task is currently paused. But thanks for the help, nevertheless!
chunwong replied on at Permalink Reply
Hi Jordan,

Stumbled upon your solution by luck. Seemed like an easy method to hardcode a custom form. Followed your instructions and had a custom form in seconds.

Unfortunately, nothing happens on submit? =(

Only things I've changed are the block names, as instructed and changed the input fields in view.php. In the Dashboard > Reports > Form Results, the new Custom Form is visible, but the # of submissions stays 0. Guess the form is just being cocky and doesn't wants to cooperate =P

PS: when I inspect the form, the action attr. is empty?

Any ideas?
jordanlev replied on at Permalink Reply
Not sure... I've since put this code on github, which might be a more up-to-date version of the code. I'd try that (click the "ZIP" button near the top-left of the page to download the files).

Hope that helps!


EDIT: Oops, forgot the link:https://github.com/jordanlev/c5_custom_contact_form...
chunwong replied on at Permalink Reply
Found out the hardcoded way doesn't work for Forms, so I just created a new Area and added the form that way.

Works awesome, thnx for sharing ;)