?
Solved

TEXTAREA submission limit

Posted on 2001-06-20
8
Medium Priority
?
434 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 400 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

719 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