Jump to content

How to make phone number mandatory


vm0824

Recommended Posts

Hello,

   I am looking to learn a bit of development for my site. One small project, is I'd like for the phone number field to be mandatory in my address blocks. Here are the steps taken so far.

  1. I was able to look in the theme and find that checkout/_partials/address-form.tpl seems to be responsible for the the checkout portion. It extends customer/_partials/address-form.tpl.
  2. customer/_partials/address-form.tpl however does not seem to list out the fields here. Instead of iterates over a $formFields variable and then creates the fields from that. 
  3. This is where I am stuck. 

Question: How do I find out where the $formFields variable is defined? And how can I edit it in a way that does not affect updates\upgrades and follows the best coding standards?

Link to comment
Share on other sites

This used to be a configuration option, however it looks like yet another feature that Prestashop has removed.  I thought maybe they moved the option to the Country settings (similar to the postal code and states), but not there either. 

 

Looks like you will need to research the following in classes\form

CustomerAddressForm.php

CustomerAddressFormatter.php

CustomerAddressPersister.php

Link to comment
Share on other sites

  • 1 month later...

Customers > Addresses > Set required fields for this section > Phone_mobile

 

Make sure youre added in locations > countries > phone_mobile 

 

You need to know about issue connected with the option "Set required fields for this section" from Back Office (at least in 1.7.1.1). 

 

Eg.: when you set the 'phone' field as 'required' and you have already customers in database who did not enter phone number during last orders, they will not able to make new orders

They will get Error 500 screen.

My customers was not able to find out why they havegot this nic error...

 

IMHO the option should has the warning about consequences it or there should check all entries in database before save new set of required fields.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
Guest mmismail

Thanks! was able to find the settings. A bit hidden, but its still there in 1.7

Can you please let me know where is that hidden settings ?

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 months later...
  • 2 months later...
  • 3 weeks later...
  • 2 months later...

If you get error 500 this is because your country/countries doesn't have the mandatory field you want to add, that's why you are getting error 500.

What happens if you want to add a mandatory field for DELIVERY ONLY or INVOICE ONLY???

 

Any ideas or where to edit? I'm not really familiar with php.

 

Regards

Link to comment
Share on other sites

  • 4 months later...

Guys, I would like to ask you this:

Is there a way to manually add a phone (or others) field in the "already-registered-customer" page? I mean, if we can add the wanted field in the customer information's page, we could "ask" them to update their infos. So, if people updates all the required fields, they shouldn't have problems.

Now, i know that saying that is simple, the problem is to find the way to "add" this field. Is there someone that knows something about that?

Link to comment
Share on other sites

  • 3 months later...

Hey guys.....This is SOLVED PS 1.7xx !!

I found the answer to this question, I was having the same issue with the phone number, I wanted the phone # mandatory.

No coding need, just a simple checked mark is needed.

In your BO > Customers > Addresses>   @ the bottom of your customer list

there is " + set required fields for this section"    click that button.

Check all fields you need, including phone number!!

Only took me 2 weeks to figure this out. I couldn't find this anywhere.

Hope this help. 

 

 

 

Edited by DEN
not solved (see edit history)
Link to comment
Share on other sites

Alright Guys, this will make the phone number mandatory in your checkout/cart

I got this to work. Hope this fix works for you.

1st go here.

In your BO > Customers > Addresses>   @ the bottom of your customer list

there is " + set required fields for this section"    click that button.

UNCHECK ALL>>>> save!!  

Next, go here>>> International>> Locations>> Countries >> for me, edit " USA "   (I only sell in the USA. This part can get tricky, for ALL the countries you have in your checkout/cart, you must do this to.)

This is how mine is setup:

firstname lastname
company
address1
address2
State:name
postcode city
phone
Country:name

SAVE YOUR WORK!!!

After setting this up, make sure this works in the checkout/cart. (for all counties) with OUT errors. Do some testing. At this point , phone will still be optional.  Again , make sure it works before moving on, very important!!!

Next >> go back to

In your BO > Customers > Addresses>   @ the bottom of your customer list

there is " + set required fields for this section"    click that button.

Now check mark ONLY the phone,   SAVE! This makes it Mandatory.

For some reason, my screen shots would not upload, sorry.

Now this is SOLVED!   Hope this help ya.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...

 I don't get this error anymore, seems to be fixed now.

I am running 1.7.4.4 and if I add the telephone as required field, existing customers that do not have that field populated, are warned that there is a field missing and the continue button is greyed out until they add it.

I simply added the mandatory field through: BO > Customers > Addresses>   @ the bottom of your customer list there is " + set required fields for this section"  click that button.

 

 

Link to comment
Share on other sites

  • 1 year later...
On 4/12/2017 at 4:43 PM, Vilius PromoApranga said:

Customers > Addresses > Set required fields for this section > Phone_mobile

Make sure youre added in locations > countries > phone_mobile 

This works perfectly in PrestaShop 1.7.2. Thanks! 

 

 

Link to comment
Share on other sites

  • 2 months later...

Hi! We were having these issues and even if in the BO we set 'phone_mobile' to be mandatory, it would reset after some time.

The solution I found was to edit the required fields list inside classes/AddressFormat.php; not sure if that's the best way but it worked for us.

Edited by airtogazta
typo (see edit history)
Link to comment
Share on other sites

  • 3 weeks later...
On 10/1/2020 at 11:34 AM, airtogazta said:

Hi! We were having these issues and even if in the BO we set 'phone_mobile' to be mandatory, it would reset after some time.

The solution I found was to edit the required fields list inside classes/AddressFormat.php; not sure if that's the best way but it worked for us.

Same problem, after some time, it resets

Link to comment
Share on other sites

  • 4 months later...

Same problem here I've updated to newest 1.7.7.2 and after I save required fields it works and I got new record inside ps_required_field but when refresh form it resets. All records from ps_required_field diapered.

Change AddressFormat.php and adding there phone to required fields helps so probably the best way will be create override fot this class. 

Edited by nikos83 (see edit history)
  • Like 1
Link to comment
Share on other sites

On 3/16/2021 at 2:45 PM, nikos83 said:

Same problem here I've updated to newest 1.7.7.2 and after I save required fields it works and I got new record inside ps_required_field but when refresh form it resets. All records from ps_required_field diapered.

Change AddressFormat.php and adding there phone to required fields helps so probably the best way will be create override fot this class. 

Confirming this solution. I just was about to recommend the same.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...