Forums

problem with strlen() - (counting chars)

gilloux7 13 Dec, 2008
Hi everybody :-)
I'm working with latest chronoform and joomla 1.5.7...
I've built a form witch use javascript to limit textarea to 4000 chars.
Everything's okay but I need a server validation for people trying to deactivate javascript or simply use a browser that don't support it fully.
The problem is :

If i submit this form with a fully loaded textarea of 4000 chars then the server tell me this is too much !
I've tried a lot : strlen() mb_strlen($string,'UTF-8'), stripslashes before counting chars...
everytime my variable is over 4000...

So I understand it has to do with what append to the data before the validation script run...
Somebody has an idea about this ?

Thanks very much if you can help...
Max_admin 14 Dec, 2008
Hi gilloux7,

did you try the server validation in Chronoforms ? you can count the posted string from this textarea and display some error ?

regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gilloux7 15 Dec, 2008
Hi Max,
This is exactly what I do !
I put my validation code in the right tab but mb_strlen() php function returns more chars that's expected...
I suppose chronoforms add something in the textarea before the validation script...?
GreyHead 15 Dec, 2008
Hi gilloux,

Is the problem that mb_strlen counts multi-byte characters as '1'? The Notes in the php manual suggest using mb_strlen($string, '8bit'); to count the byte length.

Bob
gilloux7 15 Dec, 2008
Hi Bob,
The problem is that my javascript counts correctly the numbers of chars in the textarea but php on the validation side, counts more ! So I think mb_strlen count enough chars... something adds a few things in the texarea before the validation script I guess...
Thanks for your answer guys ! I feel less alone with this strange problem !
GreyHead 15 Dec, 2008
Hi gilloux,

I don't think that anything is added - at least not deliberately :-(

Bob
gilloux7 15 Dec, 2008

Hi gilloux,

I don't think that anything is added - at least not deliberately :-(

Bob


thanks bob,
not deliberately i think so...
And now you know what ?
This bite of code return me a T variable error..
Do you find it ?
<?php
$introlimit=501;
$fullimit=4000;
$replace="";
$full=$_POST['fulltext'];
$full=str_replace(Chr(13), $replace, $full);
$full=str_replace(Chr(10), $replace, $full);
$full=stripslashes($full);
if(!trim($_POST['title']))
return "Désolé mais le texte a besoin d'un Titre !";
if($_POST['catid']=='none')
return "Il faut sélectionner une catégorie !";
if(!trim($_POST['introtext']))
return "Désolé mais le texte a besoin d'un résumé !";
if(!trim($_POST['fulltext']))
return "Il faut quand même écrire quelque chose !";
$much=mb_strlen($full,'UTF-8');
echo "Variable nb chars fulltext : ".$much."<br />";
echo "var full : ".mb_detect_encoding($full)."<br />";
echo "var much : ".mb_detect_encoding($much)."<br />";
if($much>$fullimit)
return "Trop de caractères dans le texte ! - Activez Javascript svp.";
?>
GreyHead 15 Dec, 2008
Hi gilloux7,

I don't see any errors in there . . . do you get any line numbers in the error message?

Bob
Max_admin 15 Dec, 2008
you may try to test the mb_strlen and strlen with some defined string first and see how they behave ? its hard to test with the real data directly if you got a problem like this.

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gilloux7 16 Dec, 2008
The error is :
Parse error: syntax error, unexpected T_VARIABLE in /Users/plume/Sites/ruedesauteurs/components/com_chronocontact/chronocontact.php(190) : eval()'d code on line 6

And i've already tried to test the mb_strlen.strlen function with simple variable witch is ok...
It's about 5 days that i'm stuck with this problem...
Ah yes I've also replced the mb_strlen with a "manual" function like this :
function new_mb_strlen( $str, $enc="" ) {
		$counts = count_chars( $str );
		$total = 0;

		// Count ASCII bytes
		for( $i = 0; $i < 0x80; $i++ ) {
			$total += $counts[$i];
		}

		// Count multibyte sequence heads
		for( $i = 0xc0; $i < 0xff; $i++ ) {
			$total += $counts[$i];
		}
		return $total;
	}

The problem is the same !
So i thought something is added somewhere by chronoform...
GreyHead 16 Dec, 2008
Hi gilloux,

I suspect that chr() is now case-sensitive and that Chr() is giving you the error.

Bob
gilloux7 16 Dec, 2008
Thanks bob but it's not... still got the error !
When I comment the str_replace() lines the error disapear (whatever the syntax), Developpers be aware of that !
I think I've found a new bug..
Does anybody master the ereg function to replace.. str_replace ?!
I just want to remove the \n\r from the textarea before the counting...
thanks
Max_admin 16 Dec, 2008
Hi gilloux7,

why do you want to replace str_replace with ereg ?

try to use the function nl2br then replace the <br> with str_replace ?I'm not sure this will work, but let me know!

Regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gilloux7 17 Dec, 2008
Ok max
I probably have some difficulty to make me understood cause english is not a usual language for me..

whatever the syntax with str_replace I have a syntax error so I thought chronoform have some difficulty with this function...
I definitly have a syntax error only with the str_replace used on the validation side... And I'm sure of the syntax though, I tried on differents server too...
So I want to try with an ereg function to confirm my diagnosis...
gilloux7 17 Dec, 2008

Hi gilloux7,

why do you want to replace str_replace with ereg ?

try to use the function nl2br then replace the <br> with str_replace ?I'm not sure this will work, but let me know!

Regards
Max


I did like this :
$full=nl2br($full);
$full=stripslashes($full);
$full=strip_tags($full);


No errors but still counting too much chars...
Max_admin 17 Dec, 2008
try to echo the $full in a textarea after submit and see what does it have exactly ?

regards
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
gilloux7 27 Dec, 2008
Hi Max
Do you mean this ?
echo '<textearea>'.$full.'</textarea>';


the result is that the code is not parsed... I see the php code in the resulting page !
gilloux7 27 Dec, 2008
If I type
</textarea>
this portion gets deleted after saving the form...

Devs, don't you think there's some bugs in the validation side of chronoforms ?
GreyHead 27 Dec, 2008
Hi gilloux,

I have no idea what the problem is any more, neither of your last two posts made any sense to me.

Please post some real examples saying exactly what is happening and we may be able to help you.

Bob
gilloux7 27 Dec, 2008
Well thanks bob !
I understand, too long time between posts...
I think i'm about to find a solution for my problem... not sure I'll tell you.
Thanks again !
Max_admin 28 Dec, 2008

Hi Max
Do you mean this ?

echo '<textearea>'.$full.'</textarea>';


the result is that the code is not parsed... I see the php code in the resulting page !



do you put it inside PHP tags ?
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.