0

I have the following Javascript I'm using to pass values from 5 textarea fields to an email function. I'm trying to create an "online workbook" where the user uses the textareas to write out their notes. The problem I'm having is that the text from the textarea fields are getting cut off and once I reach an excess of characters, not all the textarea fields are included.

Is there a way to increase that limit so all the contents within the textareas can be emailed?

<script>
function emailForm(href) {
var subject = "This form data";
var body = "Notes:\r\n\r\n";
body += "<ta1>\r\n";
body += document.getElementById("ta1").value;
body += "\r\n\r\n<ta2>\r\n";
body += document.getElementById("ta2").value;
body += "\r\n\r\n<ta3>\r\n";
body += document.getElementById("ta3").value;
body += "\r\n\r\n<ta4>\r\n";
body += document.getElementById("ta4").value;
body += "\r\n\r\n<ta5>\r\n";
body += document.getElementById("ta5").value;
body += "\r\n\r\n";
var uri = "mailto:?subject=";
uri += encodeURIComponent(subject);
uri += "&body=";
uri += encodeURIComponent(body);
window.open(uri);
}
</script> 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Send form data in an email</title>
</head>
<body>
<textarea id="ta1"></textarea>
<textarea id="ta2"></textarea>
<textarea id="ta3"></textarea>
<textarea id="ta4"></textarea>
<textarea id="ta5"></textarea>
<input type="button" onclick="emailForm();" value="Submit">
</body>
</html>

1 Answers1

0

The problem you are dealing with is about the limitation of GET requests.

When using GET requests, the total length of your method url plus query must not exceed an average of 2000 characters and this limit depends on servers and browsers both.

You can check details in here: What is the maximum length of a URL in different browsers?

To pass this issue; you should use POST requests, which also depends on server's limitation but not browsers and this limitation is generally far higher that a typical GET request's.

-------------

Since you use only HTML and leave the mailing step to the client, I've added an example form for you:

<form id="emailForm" action="mailto:someone@example.com?subject=test" 
method="post" enctype="text/plain">
Comment 1 :<br>
<textarea name="ta1" id="ta1"></textarea>
<br>
Comment 2:
<br>
<textarea name="ta2"  id="ta2"></textarea>
<br>
Comment 3:<br>
<textarea name="ta3"  id="ta3"></textarea>
<br>
Comment 4:<br>
<textarea name="ta4"  id="ta4"></textarea>
<br>
Comment 5:<br>
<textarea name="ta5"  id="ta5"></textarea>
<br>
<input type="reset" value="Reset">
<input type="submit" value="Send">

</form>
Community
  • 1
  • 1
er-han
  • 1,859
  • 12
  • 20
  • Thank you! I'm not very good at all this. Are there any resources to how I can change this code to using a 'post' request? – user2400122 Apr 27 '17 at 08:51
  • @user2400122 you're wellcome. Which language do you use? PHP, Asp.Net or something else? – er-han Apr 27 '17 at 08:59
  • I'm only working in html because I was trying to be able to use this as an "offline" option. I'm not too familiar with each, but if I have to choose, I'll choose Asp.Net. Sorry if that didn't make any sense! – user2400122 Apr 27 '17 at 09:08
  • @user2400122 I've updated the answer, see if it works for you. – er-han Apr 27 '17 at 11:30
  • Thanks @er-han. I tried this and don't see any text in the body of the email. Is it dependent on something? – user2400122 Apr 27 '17 at 15:36
  • @user2400122 I don't think it depends on something. Did you change anything? – er-han Apr 28 '17 at 08:41