Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-03-11 17:41:32

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

fInput and maxlength

Hi community,

I have this friday question:

Is there a clever (/ notsopainful) way to add the maxlength property to fInput ?

What I want here is to limit the length of the alt value for an image to 150 chars.

I thought about creating something like a new fInput2, inside txplib_forms.php, and add the maxlength property there…

But this line in txp_image.php seems problematic:

n.graf(fInput('submit', '', gTxt('save'), 'publish')).

In the case I create a fInput2 should I only add this below the line above:

n.graf(fInput2('submit', '', gTxt('save'), 'publish')).

I know there’s no dogma for the length of an alt attribute and there shouldn’t be a limit to it…

Google suggests 25 words should be enough… 150 chars will so fit the bill, for me.

And I know it’s a rather tricky question….

Tricky, Tricky, Tricky…. Ah hummm…

Last edited by hablablow (2011-03-11 17:43:48)


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

#2 2011-03-12 02:30:21

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: fInput and maxlength

You shouldn’t modify TXP’s core files, but if you did there were nothing tricky about it. You would just add the maxlenght parameter to the end of the finput()’s args, and that’s it.

Altho, the better method would be to do it with a plugin. Possibly something with JavaScript. For example something like (highly untested) could be used to add maxlenght="150" to the alt field:

/**
	Register the callback. Call xxx_maxlenght() function at
	the head_end (before closing <head> tag).
*/

 register_callback('xxx_maxlenght','admin_side','head_end');

/**
	The xxx_maxlenght function. Adds some JavaScript to the
	head
*/

function xxx_maxlenght() {

	global $event;

	/*
		End here if we are not on the images pane
	*/

	if($event != 'image')
		return;

	/*
		Adds maxlenght to the #alt-text input
	*/

	echo <<<EOF
		<script type="text/javascript">
			$(document).ready(function(){
				$('input#alt-text').attr('maxlength','150');
			});
		</script>
EOF;
}

If you don’t want to use JavaScript and a plugin, the other really easy method is tweaking the database a bit. You could change the txp_image table’s alt field’s lenght in to 150 from the default 255.

Yep, the alt text is already limited to 255 chars. If you want to change it to 150 you could do it easy with any DB management tool, or by running following query for example with phpMyadmin (highly untested, backup before trying):

ALTER TABLE txp_image CHANGE alt alt VARCHAR(150) CHARACTER SET utf8 NOT NULL DEFAULT ''

hablablow wrote:

In the case I create a fInput2 should I only add this below the line above:

That’s the save button. Are you sure that’s the correct location ;)

Last edited by Gocom (2011-03-12 02:32:26)

Offline

#3 2011-03-12 10:57:29

hablablow
Member
From: Paris
Registered: 2004-12-13
Posts: 309
Website

Re: fInput and maxlength

Wow Jukka thanks !
You made my day !

As for the 3 paths you suggest, I’ll walk through the shortest one: Sql.

Kthanks !

Dang mama, I love this Textpattern stuff !


_
_I plant seeds for future visions. Farmer of your eyes. Subliminal engineer of your minds. eion founder__

Hablablow + Webdesignofficina

Offline

Board footer

Powered by FluxBB