# Forms extension

**URL:** <https://www.ruby-forum.com/t/forms-extension/199026>\
**Category:** Radiant CMS\
**Created:** [November 12, 2010, 4:35pm UTC](https://www.ruby-forum.com/t/forms-extension/199026 "2010-11-12T16:35:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@Dobai-Pataky\_BSSSSl](https://www.ruby-forum.com/u/Dobai-Pataky_BSSSSl)\
**Post date:** [November 12, 2010, 4:35pm UTC](https://www.ruby-forum.com/t/forms-extension/199026/1 "2010-11-12T16:35:51Z")

</div>

Has anyone used a forms/mailer extension for Radiant that allows a file  
to  
be attached and sent with the form? I have a form working – users fills  
in  
text, selects choices from dropdown, checks radio buttons – everything  
works, contents emailed successfully. I’m trying to add the capability  
for  
people to select a file (photo) from their computer to be attached to  
the  
email but I can’t get it to work. If you’ve got it working, could you  
please  
share your solution?

Many thanks.

---

<div class="post-metadata">

**Author:** ![Marshal\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@Marshal\_L](https://www.ruby-forum.com/u/Marshal_L)\
**Post date:** [November 12, 2010, 5:02pm UTC](https://www.ruby-forum.com/t/forms-extension/199026/2 "2010-11-12T17:02:52Z")

</div>

On Fri, Nov 12, 2010 at 9:34 AM, Marshal L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Has anyone used a forms/mailer extension for Radiant that allows a file to  
> be attached and sent with the form? I have a form working – users fills in  
> text, selects choices from dropdown, checks radio buttons – everything  
> works, contents emailed successfully. I’m trying to add the capability for  
> people to select a file (photo) from their computer to be attached to the  
> email but I can’t get it to work. If you’ve got it working, could you please  
> share your solution?

try the aissac fork. i’ve setup mailer with attachments before and i  
think that was the fork i used (if not poke around the network and  
you’ll find it).

---

<div class="post-metadata">

**Author:** ![Marshal\_L](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@Marshal\_L](https://www.ruby-forum.com/u/Marshal_L)\
**Post date:** [November 12, 2010, 5:16pm UTC](https://www.ruby-forum.com/t/forms-extension/199026/3 "2010-11-12T17:16:43Z")

</div>

I used apotonick’s cells so that I could embed a regular Rails form  
(rendered through Rails) in a Radiant page. I found the Radiant  
extension too limiting.

This is rather involved though. What I like about it is I can embed  
arbitrarily complex forms without having to leave the Radiant rendering  
system. I plan to write this up at some point and put it in the Wiki.

At a very high - level, here’s how I did that.

1. Install cells 3.3.4 (anything higher is Rails 3 specific)

2. Added these commands so that cells can be processed from within  
Radiant (I did these in a custom extension (and the pathing reflects  
that), but you could theoretically do them anywhere in the  
initialization process, as long as you got the paths right):

3. Created cells to render my form. Here’s an example:

class QuestionInstancesCell \< ::Cell::Base  
def new  
@question\_type = QuestionType.find(@opts[‘question\_type\_id’])  
if @question\_type.question\_type =~ /FAQ/  
@question\_instance = QuestionInstance.new()  
view = :edit\_faq  
else  
@question\_instance = QuestionInstance.new(:question =\>  
@question\_type.questions.first)  
view = :edit  
end

```
 render :view => view

```

end  
end

/app/cells/question\_instances:

-rw-r–r--@ 1 weyus staff 568 Aug 30 16:46 edit.html.haml  
-rw-r–r--@ 1 weyus staff 658 Sep 6 13:21 edit\_faq.html.haml

/app/cells/question\_instances/edit.html.haml:

- type = @question\_type.question\_type
- form\_for [:admin, @question\_instance] do |f|  
= f.error\_messages  
%p  
= type  
%br/  
= f.select :question\_id, @question\_type.questions.map {|q|  
[q.question, q.id]}  
%p  
= f.label :question\_text, “Edit the question to best fit your  
selling situation”  
%br/  
= f.text\_area :question\_text, :value =\>  
@question\_type.questions.first.question, :class =\> ‘short’  
%p  
= f.label :new\_form, “Would you like to build another #{type}  
question?”  
= check\_box\_tag :new\_form, 1, false  
%p  
= submit\_tag ‘Submit’

1. Created a custom tag to allow for a cell to be rendered inside of a  
Radiant template:

2. Call the tag from my Radiant template:

\<r:cell name=“question\_instances” view=“new” question\_type\_id=“9”/\>

Wes
