Jump to content
  • Checkout
  • Login
  • Get in touch


The e-commerce.

sloppy words cleaner header tag versus hook


Recommended Posts

Hello folks,

I'm thinking about an update for the Sloppy Words Cleaner

Just for those who do not know it:

What does this contrib do?
Like the title says... cleans up the sloppy inputted words by customers on their registration, edit account etc.
I also added a all lowercase for the email strings. explain sloppy input?
OK, new customer creates a new account as:
123 noWHERe ave.
canton, NY 12345
email: BIGred@AOL.com
this will be cleaned (and stored in your db) and displayed on all invoices/screen info-text as:
John Doesky
123 Nowhere Ave.
Canton, NY 12345
email: bigred@aol.com
I also added exception words (you can add or remove these exception words to your liking!)
i.e. "PO" for PO Box 1234 (allowing a capital "O" after the capital "P")
"IV" for John Doe IV (instead of John Doe Iv)
"RR 2" for Rural Route 2 (instead of Rr 2)

Also includes exception arrays for Names like: "Mc" and "Mac", "De la Rosa" etc.: JOHN MACDONALD  will get John MacDonald


I plan to modularize it for 2.3.4 BS community version and avoid core file changes as much as possible.

Now my doubt is to realize this with a header tag ot hook:


+ fits in just in the right place on each page to filter the data before saved in the database
+ no extra database queries
- core file changes (hook call) on each page where it should be applied (create_account.php, account_edit.php, checkout_shipping_address.php, checkout_payment_address.php)
- additional configuration entries, install function in hook, but uninstall not so smooth (remove hook then set uninstall to "true" etc.)

Header Tag:

+ no core file changes, upload header tag, install, serves for all pages via selectable page list
+ all configuration entries, custom exception lists etc integrated in header tag module
- header tag is called in template_top when data is already written to database -> needs to be used in the next page (create_account_success.php for create_account.php) and read all data again out of database -> apply filter function -> write back into database. Ergo additional queries-> slows down the process.

Header tag with javascript filter on the fly? not so happy with it :sad:

Any opinion or coment very welcome




Link to comment
Share on other sites

Many store owners use it already who do not like to print these kind of address labels:

123 noWHERe ave.
canton, NY 12345

I agree for company names, there is all allowed, but for name, address, e-mail there are common rules for upper/lower case :-)

Link to comment
Share on other sites

OK, but it's the same problem, the data is already processed and written into database.


//filter should be applied here to all customer variables

      tep_db_perform(TABLE_CUSTOMERS, $sql_data_array);

      $customer_id = tep_db_insert_id();


      tep_db_perform(TABLE_ADDRESS_BOOK, $sql_data_array);

// header tags are loaded here

Or do you refer to manipulate the input field contents before form submit, how? javascript?

Edited by raiwa
Link to comment
Share on other sites

Hook it is then.  It's a good use of Hooking.

Bear in mind that in the English language, getting it 100% correct is difficult;


All are valid surnames.  In addition "Macdonald" can also be a given (first) name!

Edited by burt
Link to comment
Share on other sites

Will see if these exceptions can be all built in, thanks.

There are already separate exception arrays included for first name, second name and other data.

They are just hardcoded in the function file until now and I'll move them to user editable configuration settings.

Edited by raiwa
Link to comment
Share on other sites

Don't forget



de Beauvoir

du Plessix

van Beethoven

von Strohm


then you have

De Quincey

Von Braun

La Rochefoucauld


and those are just surnames! You also have street names, names of cities, towns, and villages, even companies.


What if they work at the company called nVidia?


OK, I'm kind of teasing, but it's a bit of a minefield.

Perhaps use javascript to capitalize words as customers are entering them in the input fields, and if it's not right they can change it?



osCommerce user since 2003! :thumbsup:

Link to comment
Share on other sites



Thanks for your suggestions.

This add-on exists since years and has already included extended exception lists.

  // exceptions to standard case conversion
   if ($is_name) {
       $all_uppercase = '';
       $all_lowercase = 'Or|And';
   } else {
   	 // address abreviations and anything else
       $all_uppercase = 'Aly|Anx|Apt|Ave|Bch|Blvd|Bldg|Bp|bp|Bsmt|Byu|Ch|Cors|Cswy|Cr|Crk|Crt|Cts|Cv|Cvs|Est|Ests|Expy|Frnt|Fl|Frks|Fwy|Gdn|Gtwy|Hbr|Hbrs|Hts|Hwy|Ii|Iii|Iv|Jct|Jcts|Lk|Lks|Ln|Ldg|Mnt|Mnr|Mnrs|Msn|Mtwy|Mtn|Mtns|Ne|Nw|Pkwy|Pl|Pln|Plns|Ph|Po|Pob|P.o.b.|P.O.b.|p.O.b.|p.o.B.|p.O.B.|Rm|Rr|Se|Skwy|Smt|Sw|Sta|Ste|Sq|Ter|Tpke|Trpk|Trlr|Trl|Trwy|Vl|Vlg|Vlgs|Vly|Vlys|Vi|Vii|Viii|Xi|Xing|Xrd';
       $all_lowercase = 'À|A|And|As|Am|An|Au|Aux|By|D|Da|De|Des|Del|Du|Der|Die|Das|En|Et|In|L|Le|La|Les|Of|Or|Ou|Sous|Sur|To|Von|Y';

// exceptions for names and surnames
	if ($is_name) {
       $all_uppercase = '';
       $all_lowercase = 'D|De La|Da|De Las|Del|De Los|Der|Van De|Van Der|Vit De|Von|Or|And|Y|En|De|La|Del|Do|Du|Am|An|Der|Die|Das';
   } else {
       $all_uppercase = '';
       $all_lowercase = 'A|And|As|By|In|Of|Or|To';
   $prefixes = "'|Mc|Mac|l'|L'";
   $suffixes = "'S";

	// replace target words
    $word = array ("Saint" => "St","Sainte" => "Ste","Saints" => "Sts", "Saintes" => "Stes");
	return strtr($str,$word);


To cover the allowed variation examples given by burt and you, I'll add now an array with terms which will not be altered by the filter function:

$exception_terms = 'McDonald|MacDonald|Macdonald|Mcdonald|De Quincey|La Rochefoucauld';

I can't confirm the third case "Von Braun". The most famous reresentative is spelled "Wernher von Braun", there may be other examples, but as always, 100% is impossible, but most store owners will prefer to get 99.9% clean data and 0.1 % or less with these kind of errors.

As already stated, all of these lists are in the old version hardcoded in the function file, but will now be editable in admin as configuration settings. So each store owner can adapt them to his local needs and language.

I can say that I'm using this since many years on my wife's store, and after adding some spanish and german exceptions which were not included in the original add-on, we didn't have to correct any data since years. Other users reported the same.

For on the fly javascript filtering:

- it would be quite a long script and slow down page load
- if a customer stops typing before he finished, and clicks out of the field, filter function would be triggered and he may get unexpected results and may get confused
- if the correction is done on the fly, even they finished typing, they also may get confused and not understand what happened
- create account is a sensitive process mostly done for checkout. I won't like to confuse any customer during this process
- once they are registered and see their corrected data it's less problematic and they will understand it easier

tks a lot for your time and suggestions



Link to comment
Share on other sites



Forgot to mention:

For Company names any spelling is allowed, so no filtering applies to the company field.

Each entrance can be treated by different filter funtions.

Link to comment
Share on other sites

Just to remind: this topic is header tag versus hook for the new modularized version

If you wish to see what the existing add-on already does, you are invited to download it and try:

Sloppy Words Cleaner

Link to comment
Share on other sites



I already use this addon, and it has saved countless hours in getting customer details and addresses almost 100% correctly formatted.

Whether it would be better as a hook or header tag I have no real preference, but a header tag may be easier with all the core pages that the hook code would need adding to. Also having less core code changes may make upgrading the store easier in the future, unless it is possible to alter the core files required for a change automatically, which i very much doubt.


Link to comment
Share on other sites


Thanks Steve, the big minus for header tag is that it loads after the data is already processed and entered in the database:


22 hours ago, raiwa said:

Header Tag:

- header tag is called in template_top when data is already written to database -> needs to be used in the next page (create_account_success.php for create_account.php) and read all data again out of database -> apply filter function -> write back into database. Ergo additional queries-> slows down the process.

So my idea was now to use hook together with a custom group module "store" which I already use in several other add ons.

It would allow to integrate an installation process which can add the few lines of additional code, (hook register and calls) in the related core files.

On uninstall theses mods can be also auto removed. This is actually what is planned for the future 2.4 Apps to do.

This "store" module can also hold all the configuration entries, exception arrays etc.




Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...