12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'app/widgets/contact_us/base.rb', line 12
def new
@is_html_form = params[:is_html_form]
@validation = {}
@validation[:first_name] = "First Name Cannot be Blank" if params[:first_name].blank?
@validation[:last_name] = "Last Name Cannot be Blank" if params[:last_name].blank?
@validation[:message] = "Message Cannot be Blank" if params[:message].blank?
@validation[:email] = "Please Enter a Valid Email Address" unless /^.+@.+\..+$/.match(params[:email])
if @is_html_form and !@validation.empty?
return render :update => {:id => "#{@uuid}_result", :view => :error}
end
@website = Website.find_by_host(request.host_with_port)
@website_inquiry = WebsiteInquiry.new
subject = strip_tags(params[:email_subject])
params.delete(:email_subject)
params[:created_by] = current_user unless current_user.nil?
params[:created_with_form_id] = params[:dynamic_form_id] if params[:dynamic_form_id] and params[:is_html_form].blank?
params[:website_id] = @website.id
@website_inquiry = @website_inquiry.save_all_attributes(params, ErpApp::Widgets::Base::IGNORED_PARAMS)
if @website_inquiry
if @website.email_inquiries?
@website_inquiry.send_email(subject)
end
if @is_html_form
render :update => {:id => "#{@uuid}_result", :view => :success}
else
render :json => {
:success => true,
:response => render_to_string(:template => "success", :layout => false)
}
end
else
if @is_html_form
render :update => {:id => "#{@uuid}_result", :view => :error}
else
render :json => {
:success => false,
:response => render_to_string(:template => "error", :layout => false)
}
end
end
end
|