Home › Forums › Quform WordPress › New Filter – Uppercase first letter and make Title case
- This topic has 5 replies, 2 voices, and was last updated 7 years ago by
katw.
- AuthorPosts
- April 30, 2018 at 12:49 pm #25383
katw
ParticipantHi Ally,
I would like to create two custom field filters.
1. change first letter in the field to UPPERCASE (for NAME FIELDS for example)
2. change first letter of each discrete word to UPPERCASE (for address and title fields)Filter 2 (Title-case) use-case example: street address field with field data “unit 6/77 stone st” becomes “Unit 6/77 Stone St” and “1234 pacific hwy” becomes “1234 Pacific Hwy” etc
For filter 1 (Uppercase first word) use-case: first name field “sue-anne” becomes “Sue-anne”
I looked but couldn’t see an example to follow.
Any suggestions?
May 1, 2018 at 5:32 am #25386katw
ParticipantDon’t worry, I will do this client side.
BTW might be worth adding these filters to future QuForm updates.
And publishing a “how to make your own filter” as you have done for custom validators.
Just an idea.
May 1, 2018 at 9:58 pm #25403katw
ParticipantI tried to create a new PHP filter for uppercase first letter.
I modelled the code on your TRIM example and uploaded the new filter to the QUFORM > FILTERS directory.
Unfortunately it didn’t work.
Am guessing an Initialisation routine knows about the filters installed and didn’t like my addition. Or I have missed doing an important step.
You probably don’t want to help with this solution as I am modifying your install files (which makes it problematic for me at time of upgrading).
BUT if you did want to help here is the code I added to a file called UpperFirstLetter.PHP
<?php /** * @copyright Copyright (c)2018 ThemeCatcher */ class Quform_Filter_UpperFirstLetter extends Quform_Filter_Abstract { /** * Makes first letter of value uppercase * * If the value provided is not a string, the value will remain unfiltered * * @param string $value The value to filter * @return string The filtered value */ public function filter($value) { if ( ! is_string($value)) { return $value; } return ucfirst($value); } public static function getDefaultConfig() { $config = apply_filters('quform_default_config_filter_UpperFirstLetter', array()); $config['type'] = 'UpperFirstLetter'; return $config; } }
May 2, 2018 at 1:02 am #25412katw
ParticipantFound I should also add my new filter definition to
function getFilters()
May 2, 2018 at 4:56 pm #25450Ally
Support StaffYou don't have permission to view this content. Please log in or register and then verify your purchases to gain access.
- This reply was modified 7 years ago by
Ally.
May 3, 2018 at 11:43 pm #25491katw
ParticipantFantastic, I will follow that same format to build a title case filter too.
Thanks again.
CLOSE TICKET
- This reply was modified 7 years ago by
- AuthorPosts
- You must be logged in to reply to this topic.