# 1 form 2 actions

**URL:** <https://www.ruby-forum.com/t/1-form-2-actions/105703>\
**Category:** Rails\
**Created:** [June 1, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/1-form-2-actions/105703 "2007-06-01T16:02:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![confused2gether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@confused2gether](https://www.ruby-forum.com/u/confused2gether)\
**Post date:** [June 1, 2007, 4:02pm UTC](https://www.ruby-forum.com/t/1-form-2-actions/105703/1 "2007-06-01T16:02:11Z")

</div>

Hi I am trying to have a form submit the data in it via email using a  
php file (contact.php) that i have made but also would like it to  
store the data in my SQL db and continue on. I am using pretty much  
all AJAX in this. this is my application\_helper.rb src code. The  
section in question would be the 2nd form named tt\_form. Any ideas?

module ApplicationHelper

# Returns the name of an icon (in public/images) for the given

content type  
def icon\_for content\_type  
case content\_type.to\_s.strip  
when “image/jpeg”  
“JPG”  
when “application/vnd.ms-excel”  
“XLS”  
when “application/msword”  
“DOC”  
when “application/pdf”  
“PDF”  
else “Generic”  
end  
end

# Returns a textual description of the content type

def description\_of content\_type  
case content\_type.to\_s.strip  
when “image/jpeg”  
“JPEG graphic”  
when “application/vnd.ms-excel”  
“Excel worksheet”  
when “application/msword”  
“Word document”  
when “application/pdf”  
“PDF file”  
else “”  
end  
end

# Returns the name of the site (for the title and h1 elements)

def site\_title  
‘OpenComm’  
end

# If a page title isn’t explicitly set with @page\_title, it’s

inferred from the post or user title  
def page\_title  
return @page\_title if @page\_title  
return @post.name if @post and !@post.new\_record?  
return @user.name if @user and !@user.new\_record?  
‘’  
end

# Returns a div for each key passed if there’s a flash with that key

def flash\_div \*keys  
keys.collect { |key| content\_tag(:div, flash[key], :class =\>  
“flash #{key}”) if flash[key] }.join  
end

# Returns a div with the user’s thumbnail and name

def user\_thumb user  
img = tag(“img”, :src =\> formatted\_user\_url(:id =\> user, :format  
=\> ‘jpg’), :class =\> ‘user\_picture’, :alt =\> user.name)  
img\_link = link\_to img, user\_url(:id =\> user)  
text\_link = link\_to user.short\_name, user\_url(:id =\> user)  
content\_tag :div, “#{img\_link}  
#{text\_link}”, :class =\> ‘user’  
end

# Returns a div

def clear\_div  
‘

’  
end
# Renders the form used for all post and user creating/editing.

# Yields an instance of LabelingFormBuilder (see lib/

labeling\_form\_helper.rb).  
def standard\_form name, object, &block  
url = { :action =\> object.new\_record? ? “index” : “show” }  
html = { :class =\> “standard”,  
:style =\> (@edit\_on ? ‘’ : “display: none;”),  
:multipart =\> true }  
concat form\_tag(url, html) + “”, block.binding  
concat ‘’,  
block.binding unless object.new\_record?  
yield LabelingFormBuilder.new(name, object, self, {}, block)  
concat “” + end\_form\_tag, block.binding  
end

# Renders the form used for the IT Trouble Ticket post and user

creating/editing.

# Yields an instance of LabelingFormBuilder (see lib/

labeling\_form\_helper.rb).  
def tt\_form name, object, &block  
url = { :action =\> “contact.php”,  
:method =\> :post}  
html = { :class =\> “standard”,  
:style =\> (@edit\_on ? ‘’ : “display: none;”),  
:id =\> “ttForm”,  
:multipart =\> true }  
concat form\_tag(url, html) + “”, block.binding  
concat ‘’,  
block.binding unless object.new\_record?  
yield LabelingFormBuilder.new(name, object, self, {}, block)  
concat “” + end\_form\_tag, block.binding  
end

# Standard submit button and delete link for posts and users

def standard\_submit name=nil, object=nil  
name = post\_type unless name  
object = @post unless object  
submit\_tag(“Save #{name}”) + (object.new\_record? ? “” : (" or " +  
link\_to(“Delete”, { :action =\> ‘show’ }, :method =\> :delete, :confirm  
=\> “Are you sure?”, :class =\> “delete”)))  
end

end

---

<div class="post-metadata">

**Author:** ![confused2gether](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ee59a6/32.png) [@confused2gether](https://www.ruby-forum.com/u/confused2gether)\
**Post date:** [June 1, 2007, 4:04pm UTC](https://www.ruby-forum.com/t/1-form-2-actions/105703/2 "2007-06-01T16:04:11Z")

</div>

and in case you need it, this is my LabelingFormBuilder file too that  
the form calls to be formatted by:

class LabelingFormBuilder \< ActionView::Helpers::FormBuilder

# Overrides default field helpers, adding support for automatic

tags with

# inline validation messages.

(%w(text\_field password\_field text\_area date\_select  
file\_field)).each do |selector|  
src = \<\<-end\_src  
def #{selector}(method, options = {})  
text = options.delete(:label) || method.to\_s.humanize  
errors = @object.errors.on(method.to\_s)  
errors = errors.is\_a?(Array) ? errors.first : errors.to\_s  
html = ‘\<label for="’ + @object\_name.to\_s + ‘\_’ + method.to\_s

- ‘"\>’  
html \<\< text  
html \<\< ’ ’ + errors + ‘’ unless  
errors.blank?  
html \<\< ’ ’  
#{selector==‘date\_select’ ? “html \<\< '\<span id=”’ +  
@object\_name.to\_s + ‘\_’ + method.to\_s + ‘"\>’" : “”}  
html \<\< super  
html  
end  
end\_src  
class\_eval src, **FILE** , **LINE**  
end

end
