How can make a field required on a new address used on a shopping cart?

Dimitris Rakopoulos asked on November 27, 2014 10:37

Hello,

on the default shopping cart process, on step 3, the user is asked to enter a new address for shipping. On this form there are some required field. I want to have the phone number field required as well. Where can I define this? I was searching on the system tables but I don't think it's there. I am using version 7.0.77.

Any help is appreciated.

Thank you, Dimitris

Correct Answer

Josef Dvorak answered on November 28, 2014 09:49

Hi Dimitris,

Petar is right, Kentico 7 did not have a data driven form for the address yet, so the option is to customize the code of the control. It seems that the control is named differently in Petar's project. The default name and location is:

\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartOrderAddresses.ascx

The validation is carried out in the IsValid method.

You may also want to consider upgrade to Kentico 8, where the new checkout process uses data driven forms. This means that making a field required is a matter of changing a field setting flag.

1 votesVote for this answer Unmark Correct answer

Recent Answers


Petar Kozjak answered on November 27, 2014 15:13

Hi,

you will need to edit file: ~\CMSModules\Ecommerce\Controls\ShoppingCart\MapScriptControl.ascx.cs

In there you will need to change code. If you want to make txtBillingPhone as mandatory edit line 936:

// check billing part of the form
string result = val.NotEmpty(txtBillingName.Text.Trim(), GetString("ShoppingCartOrderAddresses.BillingNameErr"))
.NotEmpty(txtBillingAddr1.Text.Trim(), GetString("ShoppingCartOrderAddresses.BillingAddressLineErr"))
.NotEmpty(txtBillingCity.Text.Trim(), GetString("ShoppingCartOrderAddresses.BillingCityErr"))
.NotEmpty(txtBillingZip.Text.Trim(), GetString("ShoppingCartOrderAddresses.BillingZIPErr")).Result;

your code would look like this:

// check billing part of the form
string result = val.NotEmpty(txtBillingName.Text.Trim(), GetString("ShoppingCartOrderAddresses.BillingNameErr"))
.NotEmpty(txtBillingAddr1.Text.Trim(), GetString("ShoppingCartOrderAddresses.BillingAddressLineErr"))
.NotEmpty(txtBillingCity.Text.Trim(), GetString("ShoppingCartOrderAddresses.BillingCityErr"))
.NotEmpty(txtBillingZip.Text.Trim(), 
.NotEmpty(txtBillingPhone.Text.Trim(),
GetString("ShoppingCartOrderAddresses.BillingZIPErr")).Result;

also I think you will need to edit line 323 to mark required field.

Hope this helps... maybe I have missed something....

0 votesVote for this answer Mark as a Correct answer

Dimitris Rakopoulos answered on November 27, 2014 15:47

Hello,

thank you for the reply. Is this version 8? because on version 7 I cannot see this file!

Thank you, Dimitris

0 votesVote for this answer Mark as a Correct answer

Petar Kozjak answered on December 1, 2014 11:20

Hi,

yes this is 7 and sorry for wrong link...:D

0 votesVote for this answer Mark as a Correct answer

Dimitris Rakopoulos answered on December 1, 2014 11:51

Thank you for the answers! You helped me to resolve the issue.

One minor thing is that the field does not show the required field mark. I have set the asterisk as the required field mark but on this particular field it is not shown. Any ideas why?

0 votesVote for this answer Mark as a Correct answer

Josef Dvorak answered on December 1, 2014 16:10

Hi Dimitris,

The required field mark has to be shown manually, by adding attribute ShowRequiredMark="True" to the cms:LocalizeLabel control with ID "lblBillingPhone" in control ShoppingCartOrderAddresses.ascx

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.