-
Notifications
You must be signed in to change notification settings - Fork 0
/
View.ascx.cs
130 lines (109 loc) · 5.09 KB
/
View.ascx.cs
1
2
3
4
5
6
7
8
9
10
11
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
using System;
using System.Text;
using System.Web;
using DotNetNuke.Security;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Services.Localization;
using gus.Modules.DNNContactFormModule.Code;
namespace gus.Modules.DNNContactFormModule
{
public partial class View : DNNContactFormModuleModuleBase, IActionable
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack){return;}
try
{
// add the recaptcha key from module settings
if (Settings.Contains("GoogleRecaptchaCode"))
{
var key = Settings["GoogleRecaptchaCode"].ToString();
DivRecaptcha.Attributes.Add("data-sitekey", key);
}
// add attributes for HTML5 required fields
txtName.Attributes.Add("required data-errormessage-value-missing", "Must enter your name!");
txtPhone.Attributes.Add("required data-errormessage-value-missing", "Must enter your phone number!");
txtEmail.Attributes.Add("required data-errormessage-value-missing","Must enter your email address!");
txtComment.Attributes.Add("required data-errormessage-value-missing","Must enter a message!");
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
protected void btnSubmit_OnClick(object sender, EventArgs e)
{
try
{
var name = txtName.Text;
var EnquirerEmail = txtEmail.Text;
var comments = txtComment.Text;
var phone = txtPhone.Text;
var CallerIp = HttpContext.Current.Request.UserHostAddress;
var CallerAgent = HttpContext.Current.Request.UserAgent;
var CalledUrl = HttpContext.Current.Request.Url.OriginalString;
// #DEV add additional validation here, check email address.
// just make sure someone hasn't bypassed the in browser validation
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(EnquirerEmail) || string.IsNullOrEmpty(comments) ||
string.IsNullOrEmpty(phone))
{
PanelServerError.Visible = true;
}
else
{
// get the recipient email in settings (site admin)
var AdminEmail = Settings.Contains("ContactUsTargetEmailAddress")
? Settings["ContactUsTargetEmailAddress"].ToString()
: "mybackupEmail.com";
// get the localised email subject
var alias = PortalAlias.HTTPAlias;
var sub = Localization.GetString("EmailSubject.Text", LocalResourceFile) + " " + alias;
// build the email body
var body = new StringBuilder();
body.AppendLine("<p><strong>Name: </strong>" + name + "</p>");
body.AppendLine("<p><strong>Email: </strong>" + EnquirerEmail + "</p>");
body.AppendLine("<p><strong>Phone: </strong>" + phone + "</p>");
body.AppendLine("<hr>");
body.AppendLine("<p>" + comments + "</p>");
// in this instance the to and from email addresses are the same
// since this is from the web site admin to the web site admin
EmailClass.SendDNNEmail(AdminEmail, AdminEmail, body.ToString(), sub);
// log the enquiry to the DB.
DatabaseClass.InsertContactDetails(name, EnquirerEmail, phone, comments, CallerIp, CallerAgent);
// redirect if the setting is there
if (Settings.Contains("ContactUsSuccessPageUrl"))
{
var SuccessPage = Settings["ContactUsSuccessPageUrl"].ToString();
Response.Redirect(SuccessPage);
}
else
{
// otherwise, hide the form and show a success message
PanelContactUsForm.Visible = false;
PanelContactUsFormSubmitted.Visible = true;
}
}
}
catch (Exception exc)
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
public ModuleActionCollection ModuleActions
{
get
{
var actions = new ModuleActionCollection
{
{
GetNextActionID(), Localization.GetString("EditModule", LocalResourceFile), "", "", "",
EditUrl(), false, SecurityAccessLevel.Edit, true, false
}
};
return actions;
}
}
}
}