How to add phone number to the contact us form

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 年 前
Try something: batch build- select all - clean
Then
Batch build - select all - build
9 年 前
Need to see view. Not all just top bit for model and were it's being used. And same for controller
9 年 前
This is code from the ContactUs.cshtml:

@model ContactUsModel
@using Nop.Web.Models.Common;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.ContactUs").Text);
}
<div class="page contact-page">
    <div class="page-title">
        <h1>@T("PageTitle.ContactUs")</h1>
    </div>
    @Html.Action("TopicBlock", "Topic", new { systemName = "ContactUs" })
    <div class="page-body">
        @Html.Widget("contactus_top")
        @if (Model.SuccessfullySent)
        {
            <div class="result">
                @Model.Result
            </div>        
        }
        else
        {
            using (Html.BeginForm())
            {
            <div class="message-error">
                @Html.ValidationSummary(true)
            </div>
            <div class="form-fields">
                <div class="inputs-left">
                    <div class="inputs">
                        @Html.LabelFor(model => model.FullName)
                        <div class="input-box">
                            @Html.TextBoxFor(model => model.FullName, new { @class = "fullname", placeholder = T("ContactUs.FullName.Hint") })
                        </div>
                        @Html.ValidationMessageFor(model => model.FullName)
                    </div>
                    <div class="inputs">
                        @Html.LabelFor(model => model.Email)
                        <div class="input-box">
                            @Html.TextBoxFor(model => model.Email, new { @class = "email", placeholder = T("ContactUs.Email.Hint") })
                        </div>
                        @Html.ValidationMessageFor(model => model.Email)
                    </div>

                    <div class="inputs">
                        @Html.LabelFor(model => model.Phone)
                        <div class="input-box">
                            @Html.TextBoxFor(model => model.Phone, new { @class = "phone", placeholder = T("ContactUs.Phone.Hint") })
                        </div>
                        @Html.ValidationMessageFor(model => model.Phone)
                    </div>

                    @if (Model.DisplayCaptcha)
                    {
                        <div class="captcha-box">
                            @Html.Raw(Html.GenerateCaptcha())
                        </div>
                    }
                </div>
                <div class="inputs-right inputs">
                    @Html.LabelFor(model => model.Enquiry)
                    <div class="input-box">
                        @Html.TextAreaFor(model => model.Enquiry, new { @class = "enquiry", placeholder = T("ContactUs.Enquiry.Hint") })
                    </div>
                    @Html.ValidationMessageFor(model => model.Enquiry)
                </div>
            </div>
            <div class="buttons">
                <input type="submit" name="send-email" class="button-1 contact-us-button" value="@T("ContactUs.Button")" />
            </div>
            }
        }
        @Html.Widget("contactus_bottom")
    </div>
</div>

The contact us code in commonController.cs is like:

//contact us page
        [NopHttpsRequirement(SslRequirement.No)]
        public ActionResult ContactUs()
        {
            var model = new ContactUsModel()
            {
                Email = _workContext.CurrentCustomer.Email,
                Phone = _workContext.CurrentCustomer.Phone,  // I added
                FullName = _workContext.CurrentCustomer.GetFullName(),
                DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage
            };
            return View(model);
        }
        [HttpPost, ActionName("ContactUs")]
        [CaptchaValidator]
        public ActionResult ContactUsSend(ContactUsModel model, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage && !captchaValid)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
            }

            if (ModelState.IsValid)
            {
                string email = model.Email.Trim();
                string phone = model.Phone.Trim(); //added by me
                string fullName = model.FullName;
                string subject = string.Format(_localizationService.GetResource("ContactUs.EmailSubject"), _storeContext.CurrentStore.Name);

                var emailAccount = _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
                if (emailAccount == null)
                    emailAccount = _emailAccountService.GetAllEmailAccounts().FirstOrDefault();
                if (emailAccount == null)
                    throw new Exception("No email account could be loaded");

                string from = null;
                string fromName = null;
                string body = Core.Html.HtmlHelper.FormatText(model.Enquiry, false, true, false, false, false, false);
                //required for some SMTP servers
                if (_commonSettings.UseSystemEmailForContactUsForm)
                {
                    from = emailAccount.Email;
                    fromName = emailAccount.DisplayName;
                    body = string.Format("<strong>From</strong>: {0} - {1}<br /><br />{2}",
                        Server.HtmlEncode(fullName),
                        Server.HtmlEncode(email), body);
                }
                else
                {
                    from = email;
                    fromName = fullName;
                }
                _queuedEmailService.InsertQueuedEmail(new QueuedEmail()
                {
                    From = from,
                    FromName = fromName,
                    To = emailAccount.Email,
                    ToName = emailAccount.DisplayName,
                    Priority = 5,
                    Subject = subject,
                    Body = body,
                    CreatedOnUtc = DateTime.UtcNow,
                    EmailAccountId = emailAccount.Id
                });
                
                model.SuccessfullySent = true;
                model.Result = _localizationService.GetResource("ContactUs.YourEnquiryHasBeenSent");

                //activity log
                _customerActivityService.InsertActivity("PublicStore.ContactUs", _localizationService.GetResource("ActivityLog.PublicStore.ContactUs"));

                return View(model);
            }

            model.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage;
            return View(model);
        }
9 年 前
I tried the batch build, select all, clean and then batch build, select all, build. unfortunately, it is not working.


I posted all the codes I updated. Please check them for me.


Many Thanks,
9 年 前
The nopcommerce version is 3.0.
9 年 前
Checked over code looks in order. Really need to be able to debug it. Can you send over the code somehow
9 年 前
FYI, The phone input is added to the contact us form.

There is an error which is the NOP.web.framework.dll can't be found under nop.framework/bin/debug/. After the file was moved to the folder, the phone input can be seen in the contact us page.

Cheers,
7 年 前
Well, what is the solution I'm still not able to figure out. My situation is absolutely same & and I did all the above suggestions. But the problem remains. So, have anyone got any solution to add phone field in contactus page for NopCommerce 3.80, I would appreciate the help.
4 年 前
Hi,

If you want to add phone numbers, attach files etc. in the form. You can use this 3rd party plugin

https://www.nopcommerce.com/p/1713/dynamic-form-nopcommerce-plugin-contact-form-nopcommerce.aspx
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.