Jump to content

Variable changing after form submitted


elmas156

Recommended Posts

Hello everyone, I'm having a difficult time figuring out what my problem is here.  I'm trying to submit a couple of strings (to the user they are messages to be sent to other users) and I am having trouble with the string being cut off at quotation marks.  Here is the code that I'm using:

 

<?php

if (isset($_POST['submit'])) {

$staffmessage = $_POST['staffmessage'];
$studentmessage = $_POST['studentmessage'];

echo "$staffmessage<br />&nbsp<br />$studentmessage";

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<?php

$message1="This is a test message.

It does not get cut off here when the \"quotation marks\" are added.";

$message2="This is a test message.

It DOES get cut off here when the \"quotation marks\" are added.";

?>

<form name="form" method="post" action="test.php">

<textarea class="textarea" name="staffmessage" rows="12">

<?php echo $message1; ?>

</textarea></p>

<input name="studentmessage" type="hidden" value="<?php echo $message2; ?>" />

<input class="submit2" type="submit" name="submit" value="Send Message" />

</form>

</body>
</html>

 

The result that I'm getting is that when $staffmessage is echoed, I get the full message.  When $studentmessage is echoed, the message gets cut off at the first quotation mark.  The only thing that is different when creating these two variables is that $staffmessage is submitted using a "textarea" field in the form, and $studentmessage is submitted using a "hidden" field in the form.  Other than that, they are handled the exact same way.

 

Can anyone please help me figure out how to remedy this so that $studentmessage is not cut off at the quotation mark?  Thanks in advance for your help!

Link to comment
Share on other sites

Now I'm adding this code:

 

<?php
$staffmessage1 = $_POST['staffmessage'];
$studentmessage1 = $_POST['studentmessage'];

$staffmessage = htmlentities($staffmessage1);
$studentmessage = htmlentities($studentmessage1);

echo "$staffmessage<br />&nbsp<br />$studentmessage";
?>

 

and I'm getting the same result... I don't understand what's wrong here...

Link to comment
Share on other sites

I AM using htmlentities with ENT_QUOTES as the second parameter...

 


<?php

if (isset($_POST['submit'])) {

$staffmessage = $_POST['staffmessage'];
$studentmessage = $_POST['studentmessage'];

echo htmlentities($staffmessage, ENT_QUOTES);

echo "<br /> <br />";

echo htmlentities($studentmessage, ENT_QUOTES);

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>

<body>

<?php

$message1="This is a test message.

It does not get cut off here when the \"quotation marks\" are added.";

$message2="This is a test message.

It DOES get cut off here when the \"quotation marks\" are added.";

?>

<form name="form" method="post" action="test.php">

<textarea class="textarea" name="staffmessage" rows="12">

<?php echo $message1; ?>

</textarea></p>

<input name="studentmessage" type="hidden" value="<?php echo $message2; ?>" />

<input class="submit2" type="submit" name="submit" value="Send Message" />

</form>

</body>
</html>

 

The result I'm getting is the same.  Am I using htmlentities properly, or should I be doing something differently?

Link to comment
Share on other sites

Thanks again for your help.  I had tried it several different ways but it always seemed that I was getting the same result.  I found out that the problem was that my browser wasn't refreshing properly each time I would modify the code.  It's working now.

 

One other question though:  If the string that is being submitted in the textarea field is giving me the desired result, basically, it's not being cut off at the quotes, should I still use htmlentities() for it?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.