extended contact form

Topics: Developer Forum, User Forum
Nov 22, 2008 at 4:12 AM
Hi

Running the latest release ....

The current release has the contactform with:

e-mail
name
message

I'm in the need of having additional fields (including validation of the fields) - e.g. adress, zip and state etc.

I'm a newbie in .NET - but I've tried to copy the ContactForm.ascx and ContactForm.ascx.cs from the Section controls folder and renamed it to SignUpForm, In App_code /Sections I've copied the ContactForm.cs and also renamed it to SignUpForm.cs - and in all thoose copied files I've changed the references to SignUpForm and also extended the StringRex.resx by copying all entrys regarding the contactform and also named it in relation to the Signupform - but it fails big time... :0(

Does someone has a extended contactform that they want to share?

Nov 23, 2008 at 1:22 AM
Hi Wiper,

Yes I was going to post the same question. 

How hard and what do need to change to add sections to the contact form?  any ideas / help would be a really big help!

Cheers.
Nov 25, 2008 at 12:59 PM
Hi, this is really an easy section to extend.

The easiest way is to drag all new new fields to ContactForm.ascx (or any file you want) and place them where you like, and name them into exact what you are going to call them with.

<asp:TextBox ID="txtAddress" runat="server" /> <asp:RequiredFieldValidator runat="server" ID="valAddressRequired" ControlToValidate="txtAddress" ErrorMessage="Required"/>
<asp:TextBox ID="txtZip" runat="server" /> <asp:RequiredFieldValidator runat="server" ID="valZipRequired" ControlToValidate="txtZip" ErrorMessage="Required"/>
Etc....

In ContactForm.ascx.cs before txtMessage.Text.Trim(); replace it with:

string messageText = string.Empty;
messageText += "<br/>Address: " + txtAddress.Text;
messageText += "<br/>Zip: " +  txtZip.Text;
Etc.......
messageText +=  "<br/>" + txtMessage.Text.Trim();

 mail.Body = messageText;


Another way is to create a EasyControl in the same manner.
Create a new UserControl. Drag your desired fields to it and in your "Send method" add your fields to a string like above.
To get the smtp server from website just create an instance like:
WebSite _website = WebSite.GetInstance();
and then call
string smtpserver = _section.SmtpServer;
And send it.

Nov 25, 2008 at 7:52 PM
Hi richard

thx for your reply....

It sounds easy, but I'm struggling with it - have it on my local disk and precompiled it and published the site... but getting errors when I try to overwrite the existing contactform with the one I extended locally... 

I would really like to have e.g. a signup for a Newsletter form (name + e-mail - (can use the existing contactform) - and then a contact form with Name, Adress, Zip, City, Telephone, Fax, E-mail, and Message....   
  
maybe someone here would/could make it as 2 Easy controls that I just can insert? 
Nov 27, 2008 at 5:51 AM
Edited Nov 27, 2008 at 5:54 AM
Hi

I've manage to extend the form - but the new values aren't in the e-mail that I recieve 


In contactform.ascx.cs  line 69- 99 I now have:
.........

 Page.Validate(ID);
            if (Page.IsValid)
            {
                WebSite _website = WebSite.GetInstance();
                MailMessage mail;
                if (txtName.Text.Trim() != string.Empty)
                {
                    mail = new MailMessage(new MailAddress(txtEmailFrom.Text.Trim(),txtName.Text.Trim()), new MailAddress(_section.EmailTo,_section.EmailTo));
                }
                else
                {
                    mail = new MailMessage(txtEmailFrom.Text.Trim(), _section.EmailTo);
                }
               
                if (_section.EmailCc.Trim() != string.Empty)
                    mail.CC.Add(_section.EmailCc);
                mail.SubjectEncoding = Encoding.UTF8;
                mail.Subject = _section.Subject;
                mail.BodyEncoding = Encoding.UTF8;
                mail.IsBodyHtml = false;

                string messageText = string.Empty;
                messageText += "<br/>Adress: " + txtAddress.Text;
                messageText += "<br/>Zip code: " +  txtZip.Text;
                messageText += "<br/>City: " + txtBy.Text;
                messageText += "<br/>" + txtMessage.Text.Trim();

                 mail.Body = txtMessage.Text.Trim();
                SmtpClient client = new SmtpClient(_website.SmtpServer);

......


what is missing?