if (IsPost) { if (!Context.IsValidAntiForgery()) { ModelState.AddFormError("Invalid post"); } if (MainHelper.IsEmpty(form.Name)) { ModelState.AddError("name", "Please enter your name"); } if (!MainHelper.IsEmail(form.Email)) { ModelState.AddError("email", "Please enter your email"); } if (MainHelper.IsEmpty(form.Enquiry)) { ModelState.AddError("enquiry", "Please enter a message"); } }
@functions { public bool LogAndSend(dynamic form) { // Get the variables from the form and set them in strings string strName = Html.Encode(form.Name); string strPhone = Html.Encode(form.Phone); string strAddressLine1 = Html.Encode(form.Address1); string strAddressLine2 = Html.Encode(form.Address2); string strEmailFrom = Html.Encode(form.Email); string strMessage = Library.StripHtml(form.Enquiry).ToString();
// Log the item to the XML file var filePath = Server.MapPath("~/App_Data/contact_form_log.xml"); filePath.LogContactForm(strName, strPhone, strAddressLine1, strAddressLine2, strEmailFrom, strMessage);
// Lets set the values passed in from the Macro string strEmailTo = Model.EmailTo.ToString(); string strEmailSubject = Model.EmailSubject.ToString(); var now = DateTime.Now; var strTime = String.Format("{0:HH:mm:ss}", now); var strDate = String.Format("{0:dd/MM/yyyy}", now);
// Lets Replace the placeholders in the email message body var strEmailBody = new StringBuilder(Model.EmailBody.ToString()); strEmailBody.Replace("[Name]", strName); // Find and Replace [Name] strEmailBody.Replace("[Phone]", strPhone); // Find and Replace [Phone] strEmailBody.Replace("[AddressLine1]", strAddressLine1); // Find and Replace [AddressLine1] strEmailBody.Replace("[AddressLine2]", strAddressLine2); // Find and Replace [AddressLine2] strEmailBody.Replace("[Email]", strEmailFrom); // Find and Replace [Email] strEmailBody.Replace("[Message]", strMessage); // Find and Replace [Message] strEmailBody.Replace("[Time]", strTime); // Find and Replace [Time] strEmailBody.Replace("[Date]", strDate); // Find and Replace [Date]
// Now the email is sent out to the owner, lets send out an email // to let the user know we have recieved their email & will respond shortly string strEmailReplySubject = Model.EmailReplySubject.ToString(); var strEmailReplyBody = new StringBuilder(Model.EmailReplyBody.ToString()); strEmailReplyBody.Replace("[Name]", strName); // Find and Replace [Name]
LogContactForm Creative Website Stater
I am testing the new razor CWS site. All I want to do is add Phone number to the contact form and gives me the following error.
Error loading Razor Script ContactForm.cshtml
f:\Websites\email.carbintech.net\macroScripts\ContactForm.cshtml(83): error CS1501: No overload for method 'LogContactForm' takes 6 arguments
I have been able to edit all files except for the method
LogContactForm. Can you help me to resolve this? I posted this on
codeplex and have received no response.
http://umbracocws.codeplex.com/workitem/10183 you see the error at
http://email.carbintech.net
@using System.Text
@using Creative.Website.Starter
@using umbraco.MacroEngines
@inherits DynamicNodeContext
@{
dynamic form = Context.Request.Form.ToDynamic();
if (IsPost)
{
if (!Context.IsValidAntiForgery()) { ModelState.AddFormError("Invalid post"); }
if (MainHelper.IsEmpty(form.Name)) { ModelState.AddError("name", "Please enter your name"); }
if (!MainHelper.IsEmail(form.Email)) { ModelState.AddError("email", "Please enter your email"); }
if (MainHelper.IsEmpty(form.Enquiry)) { ModelState.AddError("enquiry", "Please enter a message"); }
}
if (!IsPost || !ModelState.IsValid) {
<form method="post" action="@Node.Url">
<div class="clearfix form">
<div class="left text">
@Html.Raw(library.RemoveFirstParagraphTag(Model.FormText.ToString()))
@Html.ValidationSummary("Please review the following errors:", new { @class = "errorMessage" })
</div>
<div class="left fields">
<fieldset>
<legend>Enquiry Form</legend>
@Html.Label("Name", "name")
@Html.TextBox("name", form.Name, new { @class = !ModelState.IsValidField("name") ? "error" : string.Empty } )
<br />
@Html.Label("Phone", "Phone")
@Html.TextBox("phone", form.Phone)
@Html.Label("Address", "address1")
@Html.TextBox("address1", form.Address1)
@Html.Label("Address Line 2", "address2", new { @class = "hide" })
@Html.TextBox("address2", form.Address2)
<br />
@Html.Label("Email Address", "email")
@Html.TextBox("email", form.Email, new { @type = "email", @class = !ModelState.IsValidField("email") ? "error" : string.Empty })
<br />
@Html.Label("Enquiry", "enquiry")
@Html.TextArea("enquiry", form.Enquiry, new { @rows = 6, @cols = 25, @class = !ModelState.IsValidField("enquiry") ? "error" : string.Empty })
<br />
@Context.GetAntiForgeryHtml()
<button id="SubmitForm" type="submit">Submit Enquiry</button>
</fieldset>
</div>
</div>
</form>
}
else
{
var ok = LogAndSend(form);
if (!ok)
{
<div id="errorMailSettings">
@Model.ErrorMessage
</div>
}
else
{
// Set Thankyou text from our contact node
<div id="thankYou">
<h2>@Model.ThankYouHeaderText</h2>
@Model.ThankYouMessageText
</div>
}
}
}
@functions
{
public bool LogAndSend(dynamic form)
{
// Get the variables from the form and set them in strings
string strName = Html.Encode(form.Name);
string strPhone = Html.Encode(form.Phone);
string strAddressLine1 = Html.Encode(form.Address1);
string strAddressLine2 = Html.Encode(form.Address2);
string strEmailFrom = Html.Encode(form.Email);
string strMessage = Library.StripHtml(form.Enquiry).ToString();
// Log the item to the XML file
var filePath = Server.MapPath("~/App_Data/contact_form_log.xml");
filePath.LogContactForm(strName, strPhone, strAddressLine1, strAddressLine2, strEmailFrom, strMessage);
// Lets set the values passed in from the Macro
string strEmailTo = Model.EmailTo.ToString();
string strEmailSubject = Model.EmailSubject.ToString();
var now = DateTime.Now;
var strTime = String.Format("{0:HH:mm:ss}", now);
var strDate = String.Format("{0:dd/MM/yyyy}", now);
// Lets Replace the placeholders in the email message body
var strEmailBody = new StringBuilder(Model.EmailBody.ToString());
strEmailBody.Replace("[Name]", strName); // Find and Replace [Name]
strEmailBody.Replace("[Phone]", strPhone); // Find and Replace [Phone]
strEmailBody.Replace("[AddressLine1]", strAddressLine1); // Find and Replace [AddressLine1]
strEmailBody.Replace("[AddressLine2]", strAddressLine2); // Find and Replace [AddressLine2]
strEmailBody.Replace("[Email]", strEmailFrom); // Find and Replace [Email]
strEmailBody.Replace("[Message]", strMessage); // Find and Replace [Message]
strEmailBody.Replace("[Time]", strTime); // Find and Replace [Time]
strEmailBody.Replace("[Date]", strDate); // Find and Replace [Date]
// Now the email is sent out to the owner, lets send out an email
// to let the user know we have recieved their email & will respond shortly
string strEmailReplySubject = Model.EmailReplySubject.ToString();
var strEmailReplyBody = new StringBuilder(Model.EmailReplyBody.ToString());
strEmailReplyBody.Replace("[Name]", strName); // Find and Replace [Name]
return MainHelper.TrySendMail(strEmailTo, strEmailSubject, strEmailBody.ToString()) && MainHelper.TrySendMail(strEmailFrom, strEmailReplySubject, strEmailReplyBody.ToString());
}
}
is working on a reply...