Solved

TEXTAREA submission limit

Posted on 2001-06-20
8
422 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
 
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
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

705 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now