How To Trim Address Fields

CS-Cart does not trim off leading and trailing spaces in address fields (e.g. City, zipcode, street address, etc) entered by users. This can cause problems, e.g. leading spaces in the city and zipcode fields can cause error in realtime postage calculator.



I want to modify PHP code to trim off the leading and trailing spaces in all address fields. Can anyone point out which part of the code I need to modify?

[quote name='yong2014' timestamp='1397477627' post='181687']

CS-Cart does not trim off leading and trailing spaces in address fields (e.g. City, zipcode, street address, etc) entered by users. This can cause problems, e.g. leading spaces in the city and zipcode fields can cause error in realtime postage calculator.



I want to modify PHP code to trim off the leading and trailing spaces in all address fields. Can anyone point out which part of the code I need to modify?

[/quote]



Hi. Please use the “update_user_pre” hook which is located in the “fn_update_user” function from the “app/functions/fn.users.php” file. Hope that helps.

I never did a hook based customization in cs-cart before. So far I just jumped in and changed the code.



As I understand a hook allows for upgrade-proof customization by placing the code outside of the core app.



I see that the age_verification addon uses the update_user_pre hook. So I have some questions:


  1. Is it ok for multiple addons to do customizations using the same hook?


  2. If I want to do it the quick-and dirty way without considering upgrade-proof, can I just add my code straight in fn.users.php straight after “fn_set_hook('update_user_pre', $user_id, $user_data, $auth, $ship_to_another, $notify_user, $send_password);”?


  3. Will this fix the checkout shipping address fields in the order (by the name fn.users.php sounds just for user profiles)?

[quote name='yong2014' timestamp='1397635051' post='181790']

I never did a hook based customization in cs-cart before. So far I just jumped in and changed the code.



As I understand a hook allows for upgrade-proof customization by placing the code outside of the core app.



I see that the age_verification addon uses the update_user_pre hook. So I have some questions:


  1. Is it ok for multiple addons to do customizations using the same hook?


  2. If I want to do it the quick-and dirty way without considering upgrade-proof, can I just add my code straight in fn.users.php straight after “fn_set_hook('update_user_pre', $user_id, $user_data, $auth, $ship_to_another, $notify_user, $send_password);”?


  3. Will this fix the checkout shipping address fields in the order (by the name fn.users.php sounds just for user profiles)?

    [/quote]


  1. Yes, it will be used one-by-one using add-on priority
  2. Right
  3. The system gets order profile data from user profile data. So it should fix the fields if the second checkout step is not skipped



    Cheers

Thanks a lot eComLabs!

see also: