PDA

View Full Version : How can i stop people using caps in the title ?



Peter Jonsson
December 8, 2012, 10:20 PM
How can i stop people using caps in the title ?

Maybe even in the listing description if all are caps it shouldnt be posted.

Chris Brown
December 9, 2012, 11:18 AM
Yeah its frustrating when people either use all capitals or none at all.

There is a text-transform property for css but i think that either turns all letters to capitals or lowercase,

text-transform:uppercase; (turns text to capitals)
text-transform:capitalize; (turns first letter of each word to capital, but i think if someone typed all capitals it will stay as all capitals)
text-transform:lowercase; (turns test to lowercase)

Mike
December 10, 2012, 04:07 AM
To add error message and disallow to post it you can do following:

open includes/rlCommon.inc.php

find function checkDynamicForm

Find case "text": there and at the bottom of the "case"

just before


}
break;

case 'textarea':



add code




if( strtoupper($data[$f2]) == $data[$f2] )
{
$errors[$step] = str_replace( '{field}', '<span class="field_error">"'.$fields[$poss]['name'].'"</span>', $GLOBALS['lang']['notice_field_incorrect']);
}



it will show error for the field when they are only uppercase symbols.
Error will say "the field is incorrect"

To play with error message please change $GLOBALS['lang']['notice_field_incorrect']
to notice_field_uppercase for example
then through the languages manager add appropriate error message with key notice_field_uppercase and {field} inside the phrase body, it will be replaced with actual field name.


It's just for text field, you can do the same for textarea field in the same function.


Let me know if it's not clear or it's not working right.

Peter Jonsson
December 10, 2012, 09:45 AM
Gonna try it later today.

Thanks

Horizon
January 3, 2024, 08:34 AM
Thanks! This works great, except for one problem.
When I add this to /includes/classes/rlCommon.class.php if one of the non-required text fields is empty (no text entered), it triggers notice_field_uppercase
strtoupper(empty) matches empty.

It works great if ALLCAPS is entered to show notice_field_uppercase, but how do I not trigger notice_field_uppercase if the field is simply empty?

Horizon
January 3, 2024, 08:35 AM
Also would there be an option if ALLCAPS is detected in a text field to simply rewrite the field to lowercase?

Rudi
January 3, 2024, 09:08 AM
You need to make your text filed "required" to trigger an error that it's empty

to automatically transform text to lowercase (with the first capital letter) instead of the code below use this:


$data[$f2] = ucfirst(strtolower($data[$f2]));

Horizon
January 3, 2024, 09:23 AM
I don't necessarily want to make all text fields required though, as I have many optional ones.

I suspect I need to wrap the above with an if not empty (https://www.php.net/manual/en/function.empty.php)php statement ? but don't want to make a mistake.

Horizon
January 3, 2024, 09:24 AM
You need to make your text filed "required" to trigger an error that it's empty

to automatically transform text to lowercase (with the first capital letter) instead of the code below use this:


$data[$f2] = ucfirst(strtolower($data[$f2]));

Thanks, this actually might be better. Instead of nagging users who enter ALLCAPS, I'll just convert it if entered ALLCAPS to Allgood ;)

Horizon
January 3, 2024, 09:31 AM
Hmmm, this doesn't seem to do anything


if( strtoupper($data[$f2]) == $data[$f2] )
{
$data[$f2] = ucfirst(strtolower($data[$f2]));
}

}
break;


When adding or editing a listing, My ALLCAPS TEXT in either textarea or text remains ALLCAPS. What am I missing?

Rudi
January 3, 2024, 09:55 AM
You don't need to use 'if' statement, you should use only my code line

I forgot to mention: you need to edit this file: includes/classes/rlListings.class.php > find public function create

replace:


case 'text':
$html_fields[] = $value['Key'];

if ($value['Multilingual'] && count($GLOBALS['languages']) > 1) {
$out = '';
foreach ($GLOBALS['languages'] as $language) {
$val = $data[$fk][$language['Code']];
if ($val) {
$out .= "{|{$language['Code']}|}" . $val . "{|/{$language['Code']}|}";
}
}

$listing[$fk] = $out;
} else {
if ($value['Condition'] == 'isUrl' && ($data[$fk] == 'http://' || $data[$fk] == 'https://')) {
break;
}

$listing[$fk] = $data[$fk];
}
break;


with:


case 'text':
$html_fields[] = $value['Key'];

if ($value['Multilingual'] && count($GLOBALS['languages']) > 1) {
$out = '';
foreach ($GLOBALS['languages'] as $language) {
$val = $data[$fk][$language['Code']];
$val = ucfirst(strtolower($val));
if ($val) {
$out .= "{|{$language['Code']}|}" . $val . "{|/{$language['Code']}|}";
}
}

$listing[$fk] = $out;
} else {
if ($value['Condition'] == 'isUrl' && ($data[$fk] == 'http://' || $data[$fk] == 'https://')) {
break;
}

$listing[$fk] = ucfirst(strtolower($data[$fk]));
}
break;



then in public function edit

replace:


case 'text':
$html_fields[] = $value['Key'];

if ($value['Multilingual'] && count($GLOBALS['languages']) > 1) {
$out = '';
foreach ($GLOBALS['languages'] as $language) {
$val = $data[$fk][$language['Code']];
if ($val) {
$out .= "{|{$language['Code']}|}" . $val . "{|/{$language['Code']}|}";
}
}

$listing['fields'][$fk] = $out;
} else {
if ($value['Condition'] == 'isUrl' && $data[$fk] == 'http://') {
break;
}

$listing['fields'][$fk] = $data[$fk];
}
break;


with:


case 'text':
$html_fields[] = $value['Key'];

if ($value['Multilingual'] && count($GLOBALS['languages']) > 1) {
$out = '';
foreach ($GLOBALS['languages'] as $language) {
$val = $data[$fk][$language['Code']];
$val = ucfirst(strtolower($val));
if ($val) {
$out .= "{|{$language['Code']}|}" . $val . "{|/{$language['Code']}|}";
}
}

$listing['fields'][$fk] = $out;
} else {
if ($value['Condition'] == 'isUrl' && $data[$fk] == 'http://') {
break;
}

$listing['fields'][$fk] = ucfirst(strtolower($data[$fk]));
}
break;

Horizon
January 3, 2024, 10:18 AM
Thanks! Now it is working; however it does need a conditional, at least for my use case (and I think many)

I want to transform
ITEM SOMETHING to Item something

However I do not want to transform
Item Something to Item something

(I only want to override what someone enters in terms of Capitalization if they have their CAPS LOCK on, especially when applying to a text area where I don't want to lose all the capitalization, just override if the person has typed the whole paragraph in ALL CAPS)

Rudi
January 3, 2024, 11:07 AM
In this case, it will require a customization to check every text word for ALLCAPS

Horizon
January 3, 2024, 11:17 AM
Was just about to post after playing with this all night. I'm wondering about combining your instruction with the example if statement in post 3. Something like:


case 'text':
$html_fields[] = $value['Key'];

if ($value['Multilingual'] && count($GLOBALS['languages']) > 1) {
$out = '';
foreach ($GLOBALS['languages'] as $language) {
$val = $data[$fk][$language['Code']];
$val = ucfirst(strtolower($val));
if ($val) {
$out .= "{|{$language['Code']}|}" . $val . "{|/{$language['Code']}|}";
}
}

$listing['fields'][$fk] = $out;
} else {
if ($value['Condition'] == 'isUrl' && $data[$fk] == 'http://') {
break;
}
if( strtoupper($data[$fk]) == $data[$fk] )
{
$listing['fields'][$fk] = ucfirst(strtolower($data[$fk]));
}
else {
$listing['fields'][$fk] = $data[$fk];
}
}
break;

Horizon
January 3, 2024, 11:18 AM
It seems to work in practice but I'm not sure if the

if( strtoupper($data[$fk]) == $data[$fk] )
is safe/correct to use in that context.

In limited testing so far,
ALL CAPS changes to All caps
no caps stays no caps
Some Caps stays Some Caps

(I only have one language on my site so I didn't apply to the multilingual section)

P.S. thanks again for taking all the time tonight to look at this!

Horizon
January 3, 2024, 11:39 AM
I think the above post 14 works for text and textarea if it's safe to use.

The above does seem to work to prevent 100% ALL CAPS in a field, but it won't do anything if it's 99% all caps.

Reading again what you posted, I see your point too now. The ideal would probably be a more complex customization that calculates the percentage of all caps in a field and forces lower case if it's over 90% all caps if it's over x-number of characters to allow a few cases where a field will be all caps like a three letter all caps model name, but prevent cases where someone is typing a whole sentence unnecessarily in ALL CAPS.

The above seems to at least have limited functionality for me though so I like that. I have a number of more important customizations that I'm going to have you do first, so I'll use this for now and then come back to it once I have everything rolling and request a customization with more functions probably!

Thanks again for all your time tonight and taking the time to look at this!