Making Customer Fields Required for Product Template - AC Gold
You can make requirement for a customer to enter text into a customer field. Let's suppose you have a product template that has two customer fields where they can enter a personalization like a monogram for example. There is a way to require the customer enter something in that field before adding it to the cart.
In order to accomplish this task edit the following file.
Code/ProductHelper.cs
Locate and replace the BuildProductChoices function with the following method and keep one more thing in your mind that replace the method in case that you haven't customized this method before otherwise replace operation will cause the lose of your customized work. In this situation you need to merge this code with your custom code.
public static void BuildProductChoices(Product product, PlaceHolder phChoices) { // ADD IN THE PRODUCT TEMPLATE CHOICES foreach (ProductTemplate template in product.ProductTemplates) { foreach (InputField input in template.InputFields) { if (!input.IsMerchantField) { // ADD THE CONTROL TO THE PLACEHOLDER phChoices.Controls.Add(new LiteralControl("<tr><td colspan=\"2\">")); phChoices.Controls.Add(new LiteralControl((input.UserPrompt + "<br />"))); WebControl o = input.GetControl(); if (o != null) { phChoices.Controls.Add(o); if (input.InputType == InputType.TextBox) { RequiredFieldValidator rfv = new RequiredFieldValidator(); rfv.ID = "rfv" + input.Id.ToString(); rfv.ControlToValidate = o.ID; rfv.Text = "*"; rfv.ValidationGroup = "AddToBasket"; phChoices.Controls.Add(rfv); } } phChoices.Controls.Add(new LiteralControl("</td></tr>")); } } } }
Now when order from store side the customer must have to provide some values for these fields, in other words you just made these fields mandatory and they can't be left blank.