Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Feb 2008
    Posts
    185
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Limit Description text area characters

    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

    Code:
    <!--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-->

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Posts
    135
    Thanks
    83
    Thanked 0 Times in 0 Posts

  • #3
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    With: maxlength="30"

    So:
    Code:
    <!--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....

  • #4
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    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

    PHP Code:
    $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

    Code:
    <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.

  • #5
    Regular Coder
    Join Date
    Feb 2008
    Posts
    185
    Thanks
    2
    Thanked 0 Times in 0 Posts

    thanks

    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?

    Code:
    $description = $_POST['description'];
    
    if (strlen($description) > 30)
    {
    print "Please limit your character length";
    }
    else
    {
    // execute script here if everythings a ok
    }

  • #6
    Regular Coder Zangeel's Avatar
    Join Date
    Oct 2007
    Location
    public_html/
    Posts
    638
    Thanks
    17
    Thanked 79 Times in 79 Posts
    It's pretty simple, see in the HTML you will see

    Code:
    <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:

    PHP Code:
    $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

    PHP Code:

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •