/    Sign up×
Community /Pin to ProfileBookmark

Form truncating message to 30 characters?

Hi all,

Hope this is the right spot for this as the question contains html, php and js…

I have a problem with a contact form. Everything behaves as it should (the form is sent, an acknowledgement is shown to the person sending the form and the completed form arrives as the correct destination) except that message cuts off at around 300 characters [I]even though the message is shown in the ‘message’ field on the page[/I]. Any ideas?

Code is below

Thanks!

—————— form——————
<form name=”contactform” id=”contactform” method=”post” action=”contact.php”>
<span class=”inputlabel”>Name:</span><br />
<input name=”name” type=”text” class=”searchbox” id=”name” size=”24″ maxlength=”50″ />
<span class=”inputlabel”>Email:</span><br />
<input name=”email” type=”text” class=”searchbox” id=”email” size=”24″ maxlength=”30″ />
<span class=”inputlabel”>Organisation (if appropriate):</span><br />
<input type=”text” name=”subject” class=”searchbox” id=”subject” size=”24″ />
<span class=”inputlabel”>Your message:</span><br />
<textarea name=”msg” cols=”45″ rows=”8″ id=”textarea”></textarea>
<br />
<input type=”button” value=”Send email” name=”send” onclick=”sendemail();” id=”submitbutton” />
</form>

——————processor——————

<?php

$to = “[email protected]“;
$subject = “From the website”; //Use this if you want to have a prefix before the subject

if(!isset($_GET[‘action’]))
{
die(“You must not access this page directly!”);
}

$name = trim($_GET[‘name’]); //The senders name
$email = trim($_
GET[’email’]); //The senders email address
$message = trim($_GET[‘msg’]); //The senders message

mail($to,$subject,$message,”From: “.$email.””); //a very simple send

echo ‘form|<h4> Dear ‘.$name.’, <br /><br />Thank you for your message. We check our email regularly and will be in touch shortly. </h4>’;
?>

——————js.——————

function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == “Microsoft Internet Explorer”){
ro = new ActiveXObject(“Microsoft.XMLHTTP”);
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function sendemail() {
var msg = document.contactform.msg.value;
var name = document.contactform.name.value;
var email = document.contactform.email.value;
var subject = document.contactform.subject.value;
document.contactform.send.disabled=true;
document.contactform.send.value=’Sending….’;

http.open(‘get’, ‘contact.php?msg=’+msg+’&name=’+name+’&subject=’+subject+’&email=’+email+’&action=send’);
http.onreadystatechange = handleResponse;
http.send(null);

}

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();

if(response.indexOf(‘|’ != -1)) {
update = response.split(‘|’);
document.getElementById(update[0]).innerHTML = update[1];

}
}

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiApr 26.2010 — You are not url encoding the message before sending it as part of the query string. Certain characters in the message could potentially break this (primary suspects would be = and &).

You also have some pretty serious security issues in this code. You are not cleaning the user input before using it to build the mail headers leaving your code open to abuse to spammers via header injection attacks. You are also directly outputting unescaped user data which could leave you open to cross site scripting (XSS) attacks.
Copy linkTweet thisAlerts:
@TimusauthorApr 26.2010 — Thanks for the reply. I have to admit its a form I've not used before (I tend to use something much simpler, or something that comes as part of a CMS) so any pointers on how to going about fixing the things you have suggested would be much appreciated.

Cheers
Copy linkTweet thisAlerts:
@TimusauthorApr 26.2010 — Also, should add that the message seems to terminate mid-word rather than on a specific character..
Copy linkTweet thisAlerts:
@tirnaApr 26.2010 — maybe the trim() is doing something strange to your message, depending on the characters in it.

One way to find out is by adding the following echo statements if you don't have a debugger.

[code=php]
echo 'Untrimmed message = '.$_GET['msg'].'<br />';

$message = trim($_GET['msg']); //The senders message

echo 'Trimmed message = '.trim($_GET['msg']); die();
[/code]


If the above trimmed and untrimmed messages are the correct user entered message, then I would output to the screen the value of any variable storing the message at every point where it is referenced in your code (which doesn't seem to be many) to see exactly where it is being truncated and then hopefully fix the cause of the problem.
Copy linkTweet thisAlerts:
@TimusauthorApr 26.2010 — Thanks for that - Ill work on it!
×

Success!

Help @Timus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...