I've searched all forums and could not find any mention of this at all. Is it at all possible to force a clean up of users input upon submitting. For instance, if they type everything in lower-case, the first letter of each word would convert to upper-case, or if they type all upper case, all but the first letter of each word would convert to lower-case.
Sloppy words cleaner
(5 posts) (2 voices)-
Posted 1 year ago #
-
simpleContact Pro does do a bit of data cleaning when a user submits the form. For example, a URL field entry will be prepended with
http://(so that it can be made into a working link) if the user neglected to enter it.There isn't a built-in function for the sort of capitalisation you mentioned, because it would be risky for me to assume what a user meant to type. However, PHP provides a function called ucwords that can be used to provide the effect you want. For example...
$formatted_string = ucwords(strtolower($string));... Would transform a string to all lower case (to iron out any mix of upper and lower case), before setting the first letter of each word in the string to upper case.
If you can supply me some more detail, about what information you want to format and at what time (e.g. for storage or simply for display) I'm sure I can suggest a code modification that would do the job.
Posted 1 year ago # -
Hello Alex,
Thank you for your reply. It's not really a big deal, but it would be cleaner looking in the database as well as the csv export if the names and addresses were all formatted the same. When an exported list is imported to a mailer for instace, the names will be exactly as the user typed them, which may look like john doe or JOHN DOE, or worse: jOHN dOE if they didn't realize they had cap locks on, but intended to type John Doe. It would really be great if the words would clean (correct themselves) while being typed. I've seen that somewhere, but cannot remember where. But just getting them cleaned up upon submission would be good enough.
For the database,
Instead of:john doe
123 any st
newark, njor
JOHN DOE
123 ANY ST
NEWARK, NJto have a cleaner format:
John Doe
123 Any St
Newark, NJTake a look at this, it may give you some ideas.
http://addons.oscommerce.com/info/5550I use it on all oscommerce sites that I develope and it works great, but I wouldn't begin to know how to incorporate it into scpro.
Thanks, Hal
Posted 1 year ago # -
Thanks for your suggestion. I think this is something I'll visit and revisit over time.
For my part, I have to try to make choices that suit all users as well as I can. For example: because a field is based on its type (e.g. long single line field) and only "Address line 1" because it has been labelled so it wouldn't be appropriate for me to assume that type of field should always transformed to proper case.
The only fields that it would be reasonable to process in this way by default are the first name and last name fields, because they are predefined for that purpose. Even then, a name like "Ronald McDonald" would be transformed to "Ronald Mcdonald" - which would be wrong from the user's point of view. You could try and anticipate every exception, but the result would be a series of hacks in the form processor.
I'll have a think about the best way to do a conversion post-submission, and post it here. You can then choose to implement it on a field-by-field basis.
That seems the best way.
Posted 1 year ago # -
Try this:
Open sc_admin/include/contact.php
To convert a submitted name to proper case, replace lines 150 and 151 with:
$name_first = ucwords(strtolower($posted["name_first"]));
$name_last = ucwords(strtolower($posted["name_last"]));After line 153, add a line of code for each of the other fields you want to convert to proper case. For example, with a field called obj_5, you would write:
$posted["obj_5"] = ucwords(strtolower($posted["obj_5"]));Please note, this code is only intended to be used with single line text fields or multi line text boxes. Menus, check box sets and radio button sets are specified by you, so users can only select from the options you provide. In fact, check box sets would error with this code, because they return an array.
Posted 1 year ago #
Reply
You must log in to post.