PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/contact.aspx

#
ASP.NET | 110 lines | 95 code | 15 blank | 0 comment | 11 complexity | 838f8deb9cab80111348ed385fd9f5fb MD5 | raw file
  1<%@ Page Language="C#" AutoEventWireup="true" Inherits="contact" ValidateRequest="false" Codebehind="contact.aspx.cs" %>
  2<%@ Import Namespace="BlogEngine.Core" %>
  3
  4<asp:content id="Content1" contentplaceholderid="cphBody" runat="Server">
  5  <div id="contact" class="contact-page page-global">
  6    <div id="divForm" runat="server">
  7      <h2 class="contact-page-title page-global-title"><%=Resources.labels.contact %></h2>
  8      <div class="contact-page-message"><%=BlogSettings.Instance.ContactFormMessage %></div>
  9        <div class="form-group">
 10          <label for="<%=txtName.ClientID %>"><%=Resources.labels.name %></label>
 11          <asp:TextBox runat="server" id="txtName" cssclass="field form-control" />
 12            <asp:requiredfieldvalidator runat="server" CssClass="required-field" controltovalidate="txtName" ErrorMessage="<%$Resources:labels, required %>" validationgroup="contact" />
 13        </div>
 14        <div class="form-group">
 15          <label for="<%=txtEmail.ClientID %>"><%=Resources.labels.email %></label> 
 16          <asp:TextBox runat="server" id="txtEmail" cssclass="field form-control" />
 17            <asp:requiredfieldvalidator runat="server"  CssClass="required-field" controltovalidate="txtEmail" ErrorMessage="<%$Resources:labels, required %>" validationgroup="contact" /> <asp:RegularExpressionValidator runat="server"   CssClass="required-field" ControlToValidate="txtEmail" display="dynamic" ErrorMessage="<%$Resources:labels, enterValidEmail %>" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" validationgroup="contact" />       
 18        </div>
 19        <div class="form-group">
 20          <label for="<%=txtSubject.ClientID %>"><%=Resources.labels.subject %></label> 
 21          <asp:TextBox runat="server" id="txtSubject" cssclass="field form-control" />
 22            <asp:requiredfieldvalidator runat="server"  CssClass="required-field" controltovalidate="txtSubject" ErrorMessage="<%$Resources:labels, required %>" validationgroup="contact" />
 23        </div>
 24        <div class="form-group">
 25          <label for="<%=txtMessage.ClientID %>"><%=Resources.labels.message %></label> 
 26          <asp:TextBox runat="server" id="txtMessage" textmode="multiline" cssclass="form-control" rows="5" columns="30" />
 27            <asp:requiredfieldvalidator runat="server"  CssClass="required-field" controltovalidate="txtMessage" ErrorMessage="<%$Resources:labels, required %>" display="dynamic" validationgroup="contact" />    
 28        </div>
 29        <div class="form-group">
 30          <asp:placeholder runat="server" id="phAttachment">      
 31            <label for="<%=txtAttachment.ClientID %>"><%=Resources.labels.attachFile %></label>
 32            <asp:FileUpload runat="server" id="txtAttachment" />
 33          </asp:placeholder>
 34        </div>
 35      <blog:RecaptchaControl runat="server" ID="recaptcha" />
 36      <asp:HiddenField runat="server" ID="hfCaptcha" />
 37      <div class="text-right btn-wrapper">
 38        <asp:button runat="server" id="btnSend" class="btn btn-primary" Text="<%$Resources:labels, send %>" OnClientClick="return beginSendMessage();" validationgroup="contact" />    
 39        <asp:label runat="server" id="lblStatus" visible="false"><%=BlogSettings.Instance.ContactErrorMessage %>.</asp:label>
 40      </div>
 41    </div>
 42    <div id="thanks">
 43      <div id="divThank" runat="Server" visible="False">      
 44      <div><%=BlogSettings.Instance.ContactThankMessage %></div>
 45      </div>
 46    </div>
 47  </div>
 48  
 49  <script type="text/javascript">
 50      function beginSendMessage() {
 51          if (BlogEngine.$('<%=txtAttachment.ClientID %>') && BlogEngine.$('<%=txtAttachment.ClientID %>').value.length > 0)
 52              return true;
 53
 54          if (!Page_ClientValidate('contact'))
 55              return false;
 56
 57          var recaptchaResponseField = document.getElementById('recaptcha_response_field');
 58          var recaptchaResponse = recaptchaResponseField ? recaptchaResponseField.value : "";
 59
 60          var recaptchaChallengeField = document.getElementById('recaptcha_challenge_field');
 61          var recaptchaChallenge = recaptchaChallengeField ? recaptchaChallengeField.value : "";
 62
 63          var name = BlogEngine.$('<%=txtName.ClientID %>').value;
 64          var email = BlogEngine.$('<%=txtEmail.ClientID %>').value;
 65          var subject = BlogEngine.$('<%=txtSubject.ClientID %>').value;
 66          var message = BlogEngine.$('<%=txtMessage.ClientID %>').value;
 67          var sep = '-||-';
 68          var arg = name + sep + email + sep + subject + sep + message + sep + recaptchaResponse + sep + recaptchaChallenge;
 69          WebForm_DoCallback('__Page', arg, endSendMessage, 'contact', onSendError, false)
 70
 71          BlogEngine.$('<%=btnSend.ClientID %>').disabled = true;
 72
 73          return false;
 74      }
 75
 76      function endSendMessage(arg, context) {
 77
 78          if (arg == "RecaptchaIncorrect") {
 79              displayIncorrectCaptchaMessage();
 80              BlogEngine.$('<%=btnSend.ClientID %>').disabled = false;
 81
 82              if (document.getElementById('recaptcha_response_field')) {
 83                  Recaptcha.reload();
 84              }
 85          }
 86          else {
 87              if (document.getElementById("spnCaptchaIncorrect")) document.getElementById("spnCaptchaIncorrect").style.display = "none";
 88
 89              BlogEngine.$('<%=btnSend.ClientID %>').disabled = false;
 90              var form = BlogEngine.$('<%=divForm.ClientID %>')
 91              var thanks = BlogEngine.$('thanks');
 92
 93              form.style.display = 'none';
 94              thanks.innerHTML = arg;
 95          }
 96      }
 97
 98      function displayIncorrectCaptchaMessage() {
 99          if (document.getElementById("spnCaptchaIncorrect")) document.getElementById("spnCaptchaIncorrect").style.display = "";
100      }
101
102      function onSendError(err, context) {
103          if (document.getElementById('recaptcha_response_field')) {
104              Recaptcha.reload();
105          }
106          BlogEngine.$('<%=btnSend.ClientID %>').disabled = false;
107          alert("Sorry, but the following occurred while attemping to send your message: " + err);
108      }
109  </script>
110</asp:content>