How to add phone number to the contact us form

5 years ago
the current contact us form only have full name, email, Enquiry. I add phone number to the contactus.cshtml in the view folder.

I got error message said that some thing missing in the contactusmodel.cs in the model folder.

It is still not working. Could anyone help me out?

Thanks,
5 years ago
Well depends what your doing:

If your changing the core, can't you just type in the phone number in the html?

If you don't want to do that, you will need to change the model and populate the model in the controller.

If you are not touching, then possibilities are using a plugin or custom theme to override the current page.

All depends on what your doing.
5 years ago
The hack workaround would be to use javascript to append the field data to the Enquiry field during submit.
5 years ago
I added the following code in the ContactUs.Cshtml:

                    <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>

I added the following code in the ContactUsModel.cs:

        [AllowHtml]
        [NopResourceDisplayName("ContactUs.Phone")]
        public string Phone { get; set; }

I updated the code in CommonController.cs:

        //contact us page
        [NopHttpsRequirement(SslRequirement.No)]
        public ActionResult ContactUs()
        {
            var model = new ContactUsModel()
            {
                Email = _workContext.CurrentCustomer.Email,
               Phone = _workContext.CurrentCustomer.Phone,//this line added
                FullName = _workContext.CurrentCustomer.GetFullName(),
                DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnContactUsPage
            };
            return View(model);
        }

I set the Nop.Web as the start up project, debugged, then built the project.


It still says:

Compiler Error Message: CS1061: 'Nop.Web.Models.Common.ContactUsModel' does not contain a definition for 'Phone' and no extension method 'Phone' accepting a first argument of type 'Nop.Web.Models.Common.ContactUsModel' could be found (are you missing a using directive or an assembly reference?)

Source Error:

Line 45:
Line 46:                     <div class="inputs">
Line 47:                         @Html.LabelFor(model => model.Phone)
Line 48:                         <div class="input-box">
Line 49:                             @Html.TextBoxFor(model => model.Phone, new { @class = "phone", placeholder = T("ContactUs.Phone.Hint") })
5 years ago
Model is missing phone. Go to the model itself and add a definition for phone
5 years ago
Is this the Model file "ContactUsModel.cs"? If this is not, where is the Model file?

Many thanks,
5 years ago
Hi yep:

namespace Nop.Web.Models.Common
{
    [Validator(typeof(ContactUsValidator))]
    public partial class ContactUsModel : BaseNopModel
    {
        [AllowHtml]
        [NopResourceDisplayName("ContactUs.Email")]
        public string Email { get; set; }

        [AllowHtml]
        [NopResourceDisplayName("ContactUs.Enquiry")]
        public string Enquiry { get; set; }

        [AllowHtml]
        [NopResourceDisplayName("ContactUs.FullName")]
        public string FullName { get; set; }

        public bool SuccessfullySent { get; set; }
        public string Result { get; set; }

        public bool DisplayCaptcha { get; set; }

        public string phone { get; set; }
    }
}
5 years ago
Yes, I added the phone to this file. But it is still not working.
5 years ago
What's the error message?  

Show your code, maybe I can help.
5 years ago
The error message is:

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS1061: 'Nop.Web.Models.Common.ContactUsModel' does not contain a definition for 'Phone' and no extension method 'Phone' accepting a first argument of type 'Nop.Web.Models.Common.ContactUsModel' could be found (are you missing a using directive or an assembly reference?)

Source Error:


Line 45:
Line 46:                     <div class="inputs">
Line 47:                         @Html.LabelFor(model => model.Phone)
Line 48:                         <div class="input-box">
Line 49:                             @Html.TextBoxFor(model => model.Phone, new { @class = "phone", placeholder = T("ContactUs.Phone.Hint") })

the code in file ContactUsModel.cs is like:

using System.Web.Mvc;
using FluentValidation.Attributes;
using Nop.Web.Framework;
using Nop.Web.Framework.Mvc;
using Nop.Web.Validators.Common;

namespace Nop.Web.Models.Common
{
    [Validator(typeof(ContactUsValidator))]
    public partial class ContactUsModel : BaseNopModel
    {
        [AllowHtml]
        [NopResourceDisplayName("ContactUs.Email")]
        public string Email { get; set; }

        [AllowHtml]
        [NopResourceDisplayName("ContactUs.Phone")]
        public string Phone { get; set; }

        [AllowHtml]
        [NopResourceDisplayName("ContactUs.Enquiry")]
        public string Enquiry { get; set; }

        [AllowHtml]
        [NopResourceDisplayName("ContactUs.FullName")]
        public string FullName { get; set; }

        public bool SuccessfullySent { get; set; }
        public string Result { get; set; }

        public bool DisplayCaptcha { get; set; }
    }
}