Solved

TEXTAREA submission limit

Posted on 2001-06-20
8
425 Views
Last Modified: 2008-03-04
I have a php/mysql page on one of the websites I work on that allows users to submit stories to a database for other uses to rate.  The problem is that I noticed that if there's too much text in the textarea where the story is put, nothing happens when I click the submit button.  I'm figure a separate possibility is to let a user upload a text file.  Could someone either tell me a way to get around the textarea limitation or give me a small simple script for allowing someone to upload a text file?  All the example scripts for uploads I have are way too complex; I would just need something simple that lets me upload a text file to the server and save it so I can just convert the saved file to a blob in the mysql db.  If you want to see exactly what I'm talking about, look at http://www.planetadnd.com/adv_tales/adv_submit.php
0
Comment
Question by:webhermit
8 Comments
 
LVL 2

Expert Comment

by:higijj
ID: 6212297
Here is the form you need to use:

<FORM ACTION="upload.php" METHOD="post" ENCTYPE="multipart/form-data">
     <B>File: <B><INPUT TYPE="FILE" NAME="userfile"><BR><BR>
     <INPUT TYPE="submit" VALUE="Upload">
</FORM>



Here is the php script to deal with the file

upload.php:

<?
$basedir = "/usr/home/";

// if the user hasn't uploaded a .txt, exit
if ($userfile_type != "text/plain") {
     print "Error! Must be a txt file!";
     exit(1);
}

$directory = $basedir . "username";
// check to see if the directory already exists
// you would need to modify this if you don't want the file to
// overwrite a previous file of the SAME user

if (is_dir($directory) && $userfile) {

     if (copy($userfile, "$directory/story.txt.php")) {
          mail_admin();
          header("Location: after_upload.php");
     } else {
          print "<HTML><BODY>Error while uploading/saving your file. Please retry. If the error still happen, please contact us.</BODY></HTML>";
     }

} else { // if it is the first time the user uploads, create his directory

     mkdir($directory, 0755);

     if ($userfile) {

          if (copy($userfile, "$directory/story.txt")) {
               mail_admin();
               header("Location: after_upload.php");
          } else {
               print "<HTML><BODY>Error while uploading/saving your file. Please retry. If the error still happen, please contact us.</BODY></HTML>";
          }

     }
}


?>
0
 
LVL 7

Expert Comment

by:daniel_c
ID: 6212438
I suggest you to do client-side script to limit textarea content.

Here is the simple example:
<html>
<head>
<script language=Javascript>

var textMax = 350; // Max length of text area = 350 chars

function checkLength(textareaObj) {
  if (textareaObj.value.length > textMax) {
     alert("Max. Length is 350 characters only!");
     textareaObj.focus();
     return false;
  }
  return true;
}

</script>
</head>
<body>
<form onSubmit="return checkLength(this.myText);">
Max. Length: 350 characters
<br>
<textarea name="myText"></textarea>
<br>
<input type-submit>
</form<
</body>
</html>

Hope this helps!

Cheers,

^_^
0
 
LVL 7

Accepted Solution

by:
daniel_c earned 100 total points
ID: 6212439
Oops, many typos! Here, it is again:

<html>
<head>
<script language=Javascript>

var textMax = 350; // Max length of text area = 350 chars

function checkLength(textareaObj) {
 if (textareaObj.value.length > textMax) {
    alert("Max. Length is 350 characters only!");
    textareaObj.focus();
    return false;
 }
 return true;
}

</script>
</head>
<body>
<form onSubmit="return checkLength(this.myText);">
Max. Length: 350 characters
<br>
<textarea name="myText"></textarea>
<br>
<input type=submit>
</form>
</body>
</html>
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Author Comment

by:webhermit
ID: 6212444
Hig -
I'll try that out and see if it works right
daniel -
The point is that I need it to let me use more, not limit them, that script's the reverse of it.
0
 

Expert Comment

by:meetyg
ID: 6214536
Your problem is that you are sending the text in the querystring! (USING the GET method in your form!)
the querystring is limited to about 2000 characters (in Internet explorer 5).
You need to send it in a form using the POST method, for example:
-------------------------------------------------
<FORM ACTION="submit_text.php" METHOD="post" ENCTYPE="multipart/form-data">

<TEXTAREA name="StoryText">
</TEXTAREA>


</FORM>
------------------------------------------------

In PHP you will be able to use the same variable as you did for the GET method, unless the register_global_variables option is off. In any case, you can get the info from the textarea like this:
-----
$MyStoryText=$HTTP_POST_VARS["StoryText"];
-----



   
0
 
LVL 2

Expert Comment

by:higijj
ID: 6224323
meetyg, read EE guideline about Proposed Answer!

you lock the question for other expert to add more comment!
if your answer is the best one, webhermit will give you the pts! ;-)
0
 
LVL 2

Expert Comment

by:higijj
ID: 6224324
webhermit, feel free to reject the above answer ..
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6419386
This question was LOCKED with a PROPOSED ANSWER and awaits your decision today.  Once a question is LOCKED with a Proposed Answer, few new experts will step in to help on that question, since the assumption is, you've been helped.  If the Proposed Answer helped you, please accept it and award that expert.  If it did not help you, please reject it and add comments as to status and what else is needed.
 
If you wish to award multiple experts, just comment here with detail, I'll respond as soon as possible.  As it stands today, you asked the question, got help and not one expert was awarded for the contribution(s) made.  Your response is needed.  I'll monitor through month end, and if you've not returned to complete this, we'll need to decide.  Expert input is welcome (as always) to determine the outcome here if the Asker does not respond.
 
Your response in finalizing this (and ALL) your question(s) is appreciated.
 
Moondancer
Community Support Moderator @ Experts Exchange

0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question