PDA

View Full Version : javascript variable character limit??



LifeIsBeta
04-24-2007, 08:19 PM
Hey all,

I have an odd situation, so bear with me.

I'm using js to populate an email via an html form on our local network. Everything was working fantastically until a user placed an unusually large amt of text into one of the textarea fields. The form just cleared out, but no resulting email was created.

Just wondering if there is a character limit that is causing this to happen? or a file size issue? or what. If so, what's a good way to break it up into smaller chunks on the fly? I know this is totally not the 'best practices' way of doing this, but you do what you have to I guess.

Thanks

boogyman
04-24-2007, 08:46 PM
are you sure that it wasn't someone trying to exploit your server via an injection?

if that was the case then you would need to do a server-side script to validate the content, which you should do anyway... but you could create a limit yourself and just display that. a normal limit for an email is something like 1024 characters, which is a full MB of data. below prints out the first "max_chars" of the string entered.



max_chars = 1024;
message = document.FORMNAME.FIELDNAME.substr(max_chars);


As this is Javascript, it is entirely client-side... you should be doing some server-side scripting before you send the email itself.




$message = substr($_REQUEST['message'], 0, 1024);

where your textarea field has the name "message"

Twey
04-24-2007, 08:53 PM
There's no problem with PHP or POST, but there might be a limit to the number of characters you can send in an email. It depends on your email server.

LifeIsBeta
04-24-2007, 09:20 PM
yes, i'm sure it wasn't an exploit of any kind, as I personally inserted an incredibly large amt of text into the form, and the form failed.

Also,
The email will handle the large amt of text, as I've pasted that text into an email, and the email goes through fine. It's definitely a breakdown between the form and the email.

Thanks for the quick replies.

Did find this out...

1500 characters works...1800 does not.

boogyman
04-24-2007, 09:34 PM
then I would say there is a limit put on by your mail server

djr33
04-24-2007, 11:18 PM
1024 characters is 1KB, not 1MB.

I've had/sent very long emails... more than that.

Perhaps a limit.

Or, are you using GET instead of POST? That may be part of it.

LifeIsBeta
04-25-2007, 12:18 PM
I'm using post



<form action="" method="post" name="emailForm" id="emailForm" onSubmit="mailForm(document.getElementById('emailForm'));">


that's on the form

This is the js



<script type="text/javascript">
<!--
function mailForm(form) {
if (!form.name == '') {
var mailto_string = 'mailto:email@email.com';
var mailto_subject = escape('!PROJECT REQUEST! - ' + form.elements['scheduled_item'].value);

var mailto_body = escape('**Tracking Number: ' + getTrackingNumber() + "\n\n" +
'**Desired Date: ' + form.elements['date_due'].value + "\n\n" +
'**Requestor Name: ' + form.elements['requestor_name'].value + "\n\n" +
'**Requestor Phone: ' + form.elements['requestor_phone'].value + "\n\n" +
'**Requestor e-Mail: ' + form.elements['requestor_email'].value + "\n\n" +
'**Item to Schedule: ' + form.elements['scheduled_item'].value + "\n\n" +

'**Point of Contact: ' + form.elements['point_of_contact'].value + "\n\n" +
'**Contact Phone: ' + form.elements['contact_phone'].value + "\n\n" +
'**Contact e-Mail: ' + form.elements['contact_email'].value + "\n\n" +

'**Request Details: ' + form.elements['request_details'].value + "\n\n" +
'**Key Benefits: ' + form.elements['key_benefits'].value + "\n");

var mailto_total = mailto_string + '?subject=' + mailto_subject + '&body=' + mailto_body;

window.location = mailto_total;
return false;
} else {
return false;
}
}

function getRadioValue(form, field) {
var obj = form.elements[field];
var checked = 0;

for (i = 0; i < obj.length; i++) {
if (obj[i].checked == true) {
return obj[i].value;
checked++;
}
}

if (checked == 0) {
return 'ERROR: Unable to retrieve radio button value.';
}
}
//-->
</script>