Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Streety 358 posts 568 karma points
    Feb 09, 2011 @ 11:17
    Streety
    0

    Email Form Code Behind

    I wondered if I could have the code behind file for the Email form.

    I'd like to make some changes and add some more field options.

    I hope you can help.

     

    regards.

  • Streety 358 posts 568 karma points
    Feb 10, 2011 @ 19:43
    Streety
    0

    I guess that's a no then.

     

    Thanks anyway.

  • Chris Koiak 700 posts 2626 karma points
    Feb 11, 2011 @ 19:24
    Chris Koiak
    2

    Sorry Streety, forgot to respond.

    The full source is already available on the projects homepage in Koiak.StandardSite.rar

    Enjoy!

    Chris

  • Streety 358 posts 568 karma points
    Feb 14, 2011 @ 10:45
    Streety
    0

    Hi Chris,

    Yes I have looked there.

    Just the BasicSiteInstall.ascx and Login.ascx are present.

    Is it not under the usercontrols directory?

     

    regards

  • Chris Koiak 700 posts 2626 karma points
    Feb 14, 2011 @ 14:44
    Chris Koiak
    0

    Ah no problem, I'll upload a new version of the code tonight

  • Streety 358 posts 568 karma points
    Feb 15, 2011 @ 17:02
    Streety
    0

    Would appreciate it.

     

    I just need to mod it to accept 7 fields instead of 5 so I need the code behind.

    Ta

  • Chris Koiak 700 posts 2626 karma points
    Feb 17, 2011 @ 10:33
    Chris Koiak
    0

    Apologies, I keep forgetting to upload this. I'll definately do it tonight.

    Chris

  • Chris Koiak 700 posts 2626 karma points
    Feb 17, 2011 @ 14:23
    Chris Koiak
    1

    This has now been uploaded.

    Cheers

  • Streety 358 posts 568 karma points
    Feb 17, 2011 @ 19:39
    Streety
    1

    Thanks for that Chris.

    Have got it.

    For the benefit of VB users I have converted your user control and also added 5 extra fields.I also removed the Form tag as my master has this already declared.

    EmailForm.ascx

     <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="EmailForm.ascx.vb" Inherits="Nine9.EmailForm" %>

    <asp:PlaceHolder ID="m_placeHolder1" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label1" runat="server" AssociatedControlID="m_textArea1">Label:</asp:Label>
    <asp:TextBox ID="m_textArea1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator1" runat="server" ControlToValidate="m_textArea1"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder2" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label2" runat="server" AssociatedControlID="m_textArea2">Label:</asp:Label>
    <asp:TextBox ID="m_textArea2" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator2" runat="server" ControlToValidate="m_textArea2"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder3" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label3" runat="server" AssociatedControlID="m_textArea3">Label:</asp:Label>
    <asp:TextBox ID="m_textArea3" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator3" runat="server" ControlToValidate="m_textArea3"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder4" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label4" runat="server" AssociatedControlID="m_textArea4">Label:</asp:Label>
    <asp:TextBox ID="m_textArea4" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator4" runat="server" ControlToValidate="m_textArea4"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder5" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label5" runat="server" AssociatedControlID="m_textArea5">Label:</asp:Label>
    <asp:TextBox ID="m_textArea5" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator5" runat="server" ControlToValidate="m_textArea5"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder6" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label6" runat="server" AssociatedControlID="m_textArea6">Label:</asp:Label>
    <asp:TextBox ID="m_textArea6" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator6" runat="server" ControlToValidate="m_textArea6"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder7" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label7" runat="server" AssociatedControlID="m_textArea7">Label:</asp:Label>
    <asp:TextBox ID="m_textArea7" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator7" runat="server" ControlToValidate="m_textArea7"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>
    <asp:PlaceHolder ID="m_placeHolder8" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label8" runat="server" AssociatedControlID="m_textArea8">Label:</asp:Label>
    <asp:TextBox ID="m_textArea8" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator8" runat="server" ControlToValidate="m_textArea8"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder9" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label9" runat="server" AssociatedControlID="m_textArea9">Label:</asp:Label>
    <asp:TextBox ID="m_textArea9" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator9" runat="server" ControlToValidate="m_textArea9"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <asp:PlaceHolder ID="m_placeHolder10" runat="server">
    <div class="formRow">
    <asp:Label ID="m_label10" runat="server" AssociatedControlID="m_textArea10">Label:</asp:Label>
    <asp:TextBox ID="m_textArea10" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="m_validator10" runat="server" ControlToValidate="m_textArea10"
    EnableClientScript="false" Display="Dynamic" ErrorMessage="Something is required." />
    </div>
    </asp:PlaceHolder>

    <div class="buttonRow">
    <asp:Button ID="m_submitButton" runat="server" CommandName="Login" Text="Log In" />
    </div>


    EmailForm.ascx.vb

    Imports System.Net.Mail

    Public Class EmailForm
    Inherits System.Web.UI.UserControl

    Dim m_ThankYouPageId As Integer
    Dim m_Recipients, m_Sender, m_ButtonText, m_Subject, m_Field1_Name, m_Field1_MandatoryMessage, _
    m_Field2_Name, m_Field2_MandatoryMessage, m_Field3_Name, m_Field3_MandatoryMessage, _
    m_Field4_Name, m_Field4_MandatoryMessage, m_Field5_Name, m_Field5_MandatoryMessage, _
    m_Field6_Name, m_Field6_MandatoryMessage, m_Field7_Name, m_Field7_MandatoryMessage, _
    m_Field8_Name, m_Field8_MandatoryMessage, m_Field9_Name, m_Field9_MandatoryMessage, _
    m_Field10_Name, m_Field10_MandatoryMessage As String

    Dim m_Field1_LargeText, m_Field2_LargeText, m_Field3_LargeText, m_Field4_LargeText, m_Field5_LargeText, _
    m_Field6_LargeText, m_Field7_LargeText, m_Field8_LargeText, m_Field9_LargeText, m_Field10_LargeText As Boolean

    Public Property ThankYouPageId() As Integer
    Get
    Return m_ThankYouPageId
    End Get
    Set(ByVal value As Integer)
    m_ThankYouPageId = value
    End Set
    End Property

    Public Property Recipients() As String
    Get
    Return m_Recipients
    End Get
    Set(ByVal value As String)
    m_Recipients = value
    End Set
    End Property

    Public Property Sender() As String
    Get
    Return m_Sender
    End Get
    Set(ByVal value As String)
    m_Sender = value
    End Set
    End Property

    Public Property ButtonText() As String
    Get
    Return m_ButtonText
    End Get
    Set(ByVal value As String)
    m_ButtonText = value
    End Set
    End Property

    Public Property Subject() As String
    Get
    Return m_Subject
    End Get
    Set(ByVal value As String)
    m_Subject = value
    End Set
    End Property

    Public Property Field1_Name() As String
    Get
    Return m_Field1_Name
    End Get
    Set(ByVal value As String)
    m_Field1_Name = value
    End Set
    End Property

    Public Property Field1_MandatoryMessage() As String
    Get
    Return m_Field1_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field1_MandatoryMessage = value
    End Set
    End Property

    Public Property Field1_LargeText() As Boolean
    Get
    Return m_Field1_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field1_LargeText = value
    End Set
    End Property

    Public Property Field2_Name() As String
    Get
    Return m_Field2_Name
    End Get
    Set(ByVal value As String)
    m_Field2_Name = value
    End Set
    End Property

    Public Property Field2_MandatoryMessage() As String
    Get
    Return m_Field2_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field2_MandatoryMessage = value
    End Set
    End Property

    Public Property Field2_LargeText() As Boolean
    Get
    Return m_Field2_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field2_LargeText = value
    End Set
    End Property

    Public Property Field3_Name() As String
    Get
    Return m_Field3_Name
    End Get
    Set(ByVal value As String)
    m_Field3_Name = value
    End Set
    End Property

    Public Property Field3_MandatoryMessage() As String
    Get
    Return m_Field3_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field3_MandatoryMessage = value
    End Set
    End Property

    Public Property Field3_LargeText() As Boolean
    Get
    Return m_Field3_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field3_LargeText = value
    End Set
    End Property

    Public Property Field4_Name() As String
    Get
    Return m_Field4_Name
    End Get
    Set(ByVal value As String)
    m_Field4_Name = value
    End Set
    End Property

    Public Property Field4_MandatoryMessage() As String
    Get
    Return m_Field4_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field4_MandatoryMessage = value
    End Set
    End Property

    Public Property Field4_LargeText() As Boolean
    Get
    Return m_Field4_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field4_LargeText = value
    End Set
    End Property

    Public Property Field5_Name() As String
    Get
    Return m_Field5_Name
    End Get
    Set(ByVal value As String)
    m_Field5_Name = value
    End Set
    End Property

    Public Property Field5_MandatoryMessage() As String
    Get
    Return m_Field5_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field5_MandatoryMessage = value
    End Set
    End Property

    Public Property Field5_LargeText() As Boolean
    Get
    Return m_Field5_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field5_LargeText = value
    End Set
    End Property

    Public Property Field6_Name() As String
    Get
    Return m_Field6_Name
    End Get
    Set(ByVal value As String)
    m_Field6_Name = value
    End Set
    End Property

    Public Property Field6_MandatoryMessage() As String
    Get
    Return m_Field6_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field6_MandatoryMessage = value
    End Set
    End Property

    Public Property Field6_LargeText() As Boolean
    Get
    Return m_Field6_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field6_LargeText = value
    End Set
    End Property

    Public Property Field7_Name() As String
    Get
    Return m_Field7_Name
    End Get
    Set(ByVal value As String)
    m_Field7_Name = value
    End Set
    End Property

    Public Property Field7_MandatoryMessage() As String
    Get
    Return m_Field7_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field7_MandatoryMessage = value
    End Set
    End Property

    Public Property Field7_LargeText() As Boolean
    Get
    Return m_Field7_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field7_LargeText = value
    End Set
    End Property

    Public Property Field8_Name() As String
    Get
    Return m_Field8_Name
    End Get
    Set(ByVal value As String)
    m_Field8_Name = value
    End Set
    End Property

    Public Property Field8_MandatoryMessage() As String
    Get
    Return m_Field8_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field8_MandatoryMessage = value
    End Set
    End Property

    Public Property Field8_LargeText() As Boolean
    Get
    Return m_Field8_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field8_LargeText = value
    End Set
    End Property

    Public Property Field9_Name() As String
    Get
    Return m_Field9_Name
    End Get
    Set(ByVal value As String)
    m_Field9_Name = value
    End Set
    End Property

    Public Property Field9_MandatoryMessage() As String
    Get
    Return m_Field9_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field9_MandatoryMessage = value
    End Set
    End Property

    Public Property Field9_LargeText() As Boolean
    Get
    Return m_Field9_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field9_LargeText = value
    End Set
    End Property

    Public Property Field10_Name() As String
    Get
    Return m_Field10_Name
    End Get
    Set(ByVal value As String)
    m_Field10_Name = value
    End Set
    End Property

    Public Property Field10_MandatoryMessage() As String
    Get
    Return m_Field10_MandatoryMessage
    End Get
    Set(ByVal value As String)
    m_Field10_MandatoryMessage = value
    End Set
    End Property

    Public Property Field10_LargeText() As Boolean
    Get
    Return m_Field10_LargeText
    End Get
    Set(ByVal value As Boolean)
    m_Field10_LargeText = value
    End Set
    End Property

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    m_submitButton.Text = ButtonText

    Field1_MandatoryMessage = If([String].IsNullOrEmpty(Field1_MandatoryMessage), "", Field1_MandatoryMessage)
    Field2_MandatoryMessage = If([String].IsNullOrEmpty(Field2_MandatoryMessage), "", Field2_MandatoryMessage)
    Field3_MandatoryMessage = If([String].IsNullOrEmpty(Field3_MandatoryMessage), "", Field3_MandatoryMessage)
    Field4_MandatoryMessage = If([String].IsNullOrEmpty(Field4_MandatoryMessage), "", Field4_MandatoryMessage)
    Field5_MandatoryMessage = If([String].IsNullOrEmpty(Field5_MandatoryMessage), "", Field5_MandatoryMessage)
    Field6_MandatoryMessage = If([String].IsNullOrEmpty(Field6_MandatoryMessage), "", Field6_MandatoryMessage)
    Field7_MandatoryMessage = If([String].IsNullOrEmpty(Field7_MandatoryMessage), "", Field7_MandatoryMessage)
    Field8_MandatoryMessage = If([String].IsNullOrEmpty(Field8_MandatoryMessage), "", Field8_MandatoryMessage)
    Field9_MandatoryMessage = If([String].IsNullOrEmpty(Field9_MandatoryMessage), "", Field9_MandatoryMessage)
    Field10_MandatoryMessage = If([String].IsNullOrEmpty(Field10_MandatoryMessage), "", Field10_MandatoryMessage)

    InitialiseFields(m_label1, m_textArea1, m_validator1, Field1_Name, Field1_LargeText, Field1_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label2, m_textArea2, m_validator2, Field2_Name, Field2_LargeText, Field2_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label3, m_textArea3, m_validator3, Field3_Name, Field3_LargeText, Field3_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label4, m_textArea4, m_validator4, Field4_Name, Field4_LargeText, Field4_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label5, m_textArea5, m_validator5, Field5_Name, Field5_LargeText, Field5_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label6, m_textArea6, m_validator6, Field6_Name, Field6_LargeText, Field6_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label7, m_textArea7, m_validator7, Field7_Name, Field7_LargeText, Field7_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label8, m_textArea8, m_validator8, Field8_Name, Field8_LargeText, Field8_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label9, m_textArea9, m_validator9, Field9_Name, Field9_LargeText, Field9_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))
    InitialiseFields(m_label10, m_textArea10, m_validator10, Field10_Name, Field10_LargeText, Field10_MandatoryMessage.Replace(vbLf, "").Replace(vbCr, ""))

    End Sub

    Protected Overrides Sub OnInit(ByVal e As EventArgs)
    MyBase.OnInit(e)
    AddHandler m_submitButton.Click, AddressOf m_submitButton_Click

    End Sub

    Private Sub InitialiseFields(ByVal label As Label, ByVal textArea As TextBox, ByVal validator As RequiredFieldValidator, ByVal name As String, ByVal largeText As Boolean, ByVal mandatoryMessage As String)
    label.Text = name

    If largeText Then
    textArea.TextMode = TextBoxMode.MultiLine
    End If

    validator.Text = mandatoryMessage
    validator.Enabled = Not [String].IsNullOrEmpty(mandatoryMessage)
    End Sub
    Protected Sub m_submitButton_Click(ByVal sender__1 As Object, ByVal e As EventArgs)
    Page.Validate()

    If Page.IsValid Then
    Dim message As New MailMessage()
    message.From = New MailAddress(Sender.Replace(vbLf, "").Replace(vbCr, ""))

    For Each recipeient As String In Recipients.Replace(vbLf, "").Replace(vbCr, "").Split(";"c)
    message.[To].Add(New MailAddress(recipeient))
    Next

    Dim body As String = "The following details were submitted to your website" & Environment.NewLine & Environment.NewLine

    body += GetFieldValue(m_label1, m_textArea1)
    body += GetFieldValue(m_label2, m_textArea2)
    body += GetFieldValue(m_label3, m_textArea3)
    body += GetFieldValue(m_label4, m_textArea4)
    body += GetFieldValue(m_label5, m_textArea5)
    body += GetFieldValue(m_label6, m_textArea6)
    body += GetFieldValue(m_label7, m_textArea7)
    body += GetFieldValue(m_label8, m_textArea8)
    body += GetFieldValue(m_label9, m_textArea9)
    body += GetFieldValue(m_label10, m_textArea10)

    body += Environment.NewLine & "Regards,"

    message.Subject = Subject.Replace(vbLf, "").Replace(vbCr, "")
    message.Body = body
    message.IsBodyHtml = False

    Dim smtpClient As New SmtpClient()
    smtpClient.Send(message)

    ' Redirect
    If ThankYouPageId > 0 Then
    Context.Response.Redirect(umbraco.library.NiceUrl(ThankYouPageId), True)
    Else
    Context.Response.Redirect("/")
    End If
    End If
    End Sub

    Private Function GetFieldValue(ByVal label As Label, ByVal textArea As TextBox) As String
    If Not [String].IsNullOrEmpty(label.Text) Then
    Return label.Text & ": " & textArea.Text & Environment.NewLine
    Else
    Return ""
    End If
    End Function

    Protected Overrides Sub OnPreRender(ByVal e As EventArgs)
    MyBase.OnPreRender(e)

    ' Disable unused fields
    m_placeHolder1.Visible = m_label1.Text.Length > 0
    m_placeHolder2.Visible = m_label2.Text.Length > 0
    m_placeHolder3.Visible = m_label3.Text.Length > 0
    m_placeHolder4.Visible = m_label4.Text.Length > 0
    m_placeHolder5.Visible = m_label5.Text.Length > 0
    m_placeHolder6.Visible = m_label6.Text.Length > 0
    m_placeHolder7.Visible = m_label7.Text.Length > 0
    m_placeHolder8.Visible = m_label8.Text.Length > 0
    m_placeHolder9.Visible = m_label9.Text.Length > 0
    m_placeHolder10.Visible = m_label10.Text.Length > 0
    End Sub

    End Class
  • adarsh 46 posts 66 karma points
    Mar 11, 2011 @ 12:01
    adarsh
    0

    hi

    could you upload the code behind file of the Login.ascx.cs

     

    i need to modify in the LoginButton_Click function in the login.ascx.cs

     

  • Chris Koiak 700 posts 2626 karma points
    Mar 11, 2011 @ 12:03
    Chris Koiak
    0

    adarsh,

    Please do not cross post. I have already answered this http://our.umbraco.org/projects/starter-kits/standard-website/general/18262-login-Form-for-codebehind

    Chris

  • adarsh 46 posts 66 karma points
    Mar 11, 2011 @ 12:14
    adarsh
    0

    Hi sorry chris.

Please Sign in or register to post replies

Write your reply to:

Draft