...

View Full Version : Limit Description text area characters



chrisjchrisj
07-02-2009, 09:44 PM
In this php script Video Upload Form, how can I limit the number of characters that can be entered into the description text area?

Thanks


<!--Begin Left Column-->
<div id="column-left-2">
<!--Begin Upload Menu-->
<div class="header-narrow"><h3>[var.lang_main_menu]</h3></div>
<div class="whats-showing">
<ul>
<li><a href="uploader.php">[var.lang_upload_video]</a></li>
<!--[var.audio_inner_upload_video_form1;htmlconv=no;comm]-->
<li><a href="image_uploader.php">[var.lang_upload_image]</a><!--[onload;block=li;when [var.enable_images]=1;comm]--></li>
</ul>
</div>
<div class="container-narrow-bottom"></div><!--End Upload Menu-->

<!--Begin Left Advert-->
<div class="container-narrow-top"></div>
<div id="advert-left">
<!--[var.ads_left;htmlconv=no;comm]-->
</div>
<div class="container-narrow-bottom"></div><!--End Left Advert-->

</div><!--End Left Column-->

<!--Begin Right Column-->
<div id="column-right-2">

<div class="header-wide"><h2>[var.lang_upload_video]</h2></div>
<div class="container-wide">
<!--BEGIN - Addon Video Grabber Code can be added in this div-->
<div>

</div>
<!--END - Addon Video Grabber Code can be added in this div-->

<!--Begin Upload Video Form-->
<form name="form_upload" action="uploader.php" method="post">
<div id="upload-video">
<ul>
<li style="width:240px; text-align:right;"><strong>[var.lang_title]:</strong></li>
<li style="width:400px; text-align:left;"><input name="title" type="text" class="upload-video-form-input" value="[var.title]" size="38" />
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_description]:</strong></li>
<li style="width:400px; text-align:left;"><textarea rows="4" name="description" cols="29" class="upload-video-form-input">[var.description]</textarea>
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_tags]:</strong></li>
<li style="width:400px; text-align:left;"><input name="tags" type="text" class="upload-video-form-input" value="[var.tags]" size="38" />
</li>

<li style="width:240px; text-align:right;">&nbsp;</li>
<li style="width:300px; text-align:left;" class="upload-video-tags">
[var.lang_enter_tags].<br />
[var.lang_enter_tags_description].</li>

<li style="width:240px; text-align:right;"><strong></strong></li>
<li style="width:400px; text-align:left;">
<input type="hidden" name="channel" value="SINGLECHANNEL"></li>


<li style="width:240px; text-align:right;"><strong></strong></li>
<li style="width:400px; text-align:left;">
<input type="hidden" name="public_private" value="public"></li>

<li style="width:240px; text-align:right">&nbsp;</li>
<li style="width:400px; text-align:left;">
<input class="button-form" type="submit" value="Next &gt;&gt;" name="B3" />
</li>
</ul>
</div>
<input class="upload-video-form-input" type="hidden" name="form_submitted" value="yes" />
</form>
<div class="clear-fix"></div>
</div>
<div class="container-wide-footer"></div>

</div><!--End Right Column-->

Sussex_Chris
07-02-2009, 10:18 PM
Check here:
http://www.mediacollege.com/internet/javascript/form/limit-characters.html

sea4me
07-03-2009, 01:20 AM
With: maxlength="30"

So:

<!--Begin Left Column-->
<div id="column-left-2">
<!--Begin Upload Menu-->
<div class="header-narrow"><h3>[var.lang_main_menu]</h3></div>
<div class="whats-showing">
<ul>
<li><a href="uploader.php">[var.lang_upload_video]</a></li>
<!--[var.audio_inner_upload_video_form1;htmlconv=no;comm]-->
<li><a href="image_uploader.php">[var.lang_upload_image]</a><!--[onload;block=li;when [var.enable_images]=1;comm]--></li>
</ul>
</div>
<div class="container-narrow-bottom"></div><!--End Upload Menu-->

<!--Begin Left Advert-->
<div class="container-narrow-top"></div>
<div id="advert-left">
<!--[var.ads_left;htmlconv=no;comm]-->
</div>
<div class="container-narrow-bottom"></div><!--End Left Advert-->

</div><!--End Left Column-->

<!--Begin Right Column-->
<div id="column-right-2">

<div class="header-wide"><h2>[var.lang_upload_video]</h2></div>
<div class="container-wide">
<!--BEGIN - Addon Video Grabber Code can be added in this div-->
<div>

</div>
<!--END - Addon Video Grabber Code can be added in this div-->

<!--Begin Upload Video Form-->
<form name="form_upload" action="uploader.php" method="post">
<div id="upload-video">
<ul>
<li style="width:240px; text-align:right;"><strong>[var.lang_title]:</strong></li>
<li style="width:400px; text-align:left;"><input name="title" type="text" class="upload-video-form-input" value="[var.title]" size="38" />
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_description]:</strong></li>
<li style="width:400px; text-align:left;"><textarea maxlength="30" rows="4" name="description" cols="29" class="upload-video-form-input">[var.description]</textarea>
</li>

<li style="width:240px; text-align:right;"><strong>[var.lang_tags]:</strong></li>
<li style="width:400px; text-align:left;"><input name="tags" type="text" class="upload-video-form-input" value="[var.tags]" size="38" />
</li>

<li style="width:240px; text-align:right;">&nbsp;</li>
<li style="width:300px; text-align:left;" class="upload-video-tags">
[var.lang_enter_tags].<br />
[var.lang_enter_tags_description].</li>

<li style="width:240px; text-align:right;"><strong></strong></li>
<li style="width:400px; text-align:left;">
<input type="hidden" name="channel" value="SINGLECHANNEL"></li>


<li style="width:240px; text-align:right;"><strong></strong></li>
<li style="width:400px; text-align:left;">
<input type="hidden" name="public_private" value="public"></li>

<li style="width:240px; text-align:right">&nbsp;</li>
<li style="width:400px; text-align:left;">
<input class="button-form" type="submit" value="Next &gt;&gt;" name="B3" />
</li>
</ul>
</div>
<input class="upload-video-form-input" type="hidden" name="form_submitted" value="yes" />
</form>
<div class="clear-fix"></div>
</div>
<div class="container-wide-footer"></div>

</div><!--End Right Column-->

And of course change 30 to how many characters would be the max.... :thumbsup:

Zangeel
07-03-2009, 09:57 AM
Can be done via html (e.g. maxlength) or javascript, but to be secure use php. Because a person can download the page, change the form action, change the html, and input more than 30 chars.

You need to give the field a name, for example name="description"

Then on the page the form action directs to use php



$description = $_POST['description'];

if (strlen($description) > 30)
{
print "Please limit your character length";
}
else
{
// execute script here if everythings a ok
}



but i would use that for EXTRA security, use the html method, or better yet, javascript to make things look better.

Here's a JS example I wrote up


<textarea id="area" onkeyup="MaxChar('area');" onkeydown="MaxChar('area')"></textarea>
<div id="textcount"><b><font color="green">30/30</font></b></div>

<script type="text/javascript">

function MaxChar(id) {

var length = document.getElementById(id).value.length;
var maxlength = 30;
var lengthleft = maxlength - length;
if (lengthleft > 0) {
document.getElementById("textcount").innerHTML = "<font color='green'><b>" + lengthleft + "/30</b></font>";
}
else {
document.getElementById("textcount").innerHTML = "<font color='red'><b>" + lengthleft + "/30</b></font>";
document.getElementById("area").disabled = true;
}
}
</script>


basically, when u press down a key, or after u lift from a key press, it will count the amount of chars in the text field, and it'll show it count down. when it hits the max (30) chars it will disable the script.

So that would be line of defense one, and next the php will stop it for sure.

chrisjchrisj
07-03-2009, 08:52 PM
Thanks for your replies. I tried Maxlength 30, but that didn't limit the description text are to 30 characters. I'd like to try the php scenario, I if i read your instructions correctly I just have to find what page the form action directs to, correct?

And then add this code somewhere on that page, correct?


$description = $_POST['description'];

if (strlen($description) > 30)
{
print "Please limit your character length";
}
else
{
// execute script here if everythings a ok
}

Zangeel
07-04-2009, 03:35 AM
It's pretty simple, see in the HTML you will see


<form name="form_upload" action="uploader.php" method="post">

This is the form action, so you will need to find the uploader.php file, because when the form is submitted is uses the php code on this page to upload all of the data.

So open uploader.php, whatever code already there just ignore.

At the very top of the page, under the <?php tag put:



$description = $_POST['description'];

if (strlen($description) > 30)
{
print "Please limit your character length";
}
else
{


then scroll to the bottom of the file, and before the ?> tag, put


}

That's a very simple way to do it, seeing uploader.php file would make this explanation way easier.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum