TEXTAREA - lines keep overwriting

A

Anonymous

Guest
Hi

I'm hoping that someone will be able to help please.

I have an 'contact us' page that has the following code within it
Code:
      <?php
$artiste = $_POST['artiste'] ;
if ($artiste == "biddles") {
  $to = 'email1';
} elseif ($artiste == "caucheteux") {
  $to = 'email2;
} else {
  $to = 'adminemail';

}									
									
									
									$subject = 'Enquiry from the website';									
									$contact_submitted = 'Your message has been sent. Thank you';									
									function email_is_valid($email) {									  
									return preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i',$email);									
									}									
									if (!email_is_valid($to)) {									  
									echo '<p style="color: red;"-->You must set-up a valid (to) email address before this contact page will work.</p>'; } 
									if (isset($_POST['contact_submitted'])) 
									{ $return = "\r"; $youremail= trim(htmlspecialchars($_POST['your_email'])); 
									$yourname =stripslashes(strip_tags($_POST['your_name'])); 
									$yourmessage =stripslashes(strip_tags($_POST['your_message'])); 
									$contact_name = "Name: ".$yourname; 
									$message_text = "   Message: ".$yourmessage; $user_answer =trim(htmlspecialchars($_POST['user_answer'])); 
									$answer =trim(htmlspecialchars($_POST['answer'])); 
									$message = $contact_name .$return .    $message_text; 
									$headers = "From: ".$youremail; 
										if (email_is_valid($youremail) && !preg_match("\r",$youremail) && !preg_match("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
										  mail($to,$subject,$message,$headers);
										  $yourname = '';
										  $youremail = '';
										  $yourmessage = '';
										  echo '<p style="color: blue;">'.$contact_submitted.'</p>';
										}
										else echo '<p style="color: red;">Please enter your name, a valid email address, your message and the answer to the simple maths question before sending your message.</p>';
									  }
									  $number_1 = rand(1, 9);
									  $number_2 = rand(1, 9);
									  $answer = substr(md5($number_1+$number_2),5,10);
								?>
      <div style="position:absolute;left:92px;top:440px;width:817px; ">
        <form id="contact" action="contactus.php" method="post">
          <div id="contact_form" class="form_settings">
            <p class="Body P-1"><span class="c-16">Name </span><input
                name="your_name" value="<?php echo $yourname; ?>" type="text"></p>
            <p class="Body P-1"><span class="c-16">Email Address </span><input
                 name="your_email" value="<?php echo $youremail; ?>"
                type="text"></p>
             <p class="Body P-1"><span class="c-16">Email Address </span> <select name="artiste">
             <option value="biddles">Robert Biddles</option>
             <option value="caucheteux">Alain Caucheteux</option>
             <option value="admin">Administrator</option>
             </select>
</p>              
            <p class="Body P-1"><span class="c-16">Message </span><textarea
rows="50" cols="50" name="your_message" value="<?php echo $yourmessage; ?>"></textarea></p>
            <p class="Body P-1">To help prevent spam, please enter the answer to
              this question:</p>
            <p class="Body P-1"><span class="c-16"><?php echo $number_1; ?> +
                <?php echo $number_2; ?> = ? </span><input name="user_answer" type="text"><input
                name="answer" value="<?php echo $answer; ?>" type="hidden"></p>
            <p style="padding-top: 15px"><span> </span><input class="button a"
name="contact_submitted" value="send" type="submit"></p>
          </div>
        </form>
      </div>

Everything is working fine, except the message box. If the sender enters a message that is longer than 1 line, or they enter a RETURN for a new line/para, the first line of text is overwritten onscreen. However, when the message is sent it arrives formatted correctly.

It will be much appreciated if someone knows how to stop this happening and for the sender to see all that they've typed.

Thanks in advance
 
I suspect it's to do with your CSS, there's no need to put form elements inside <p> elements, just format the form elements.

Check to see if you have a height for the Body or P-1 classes.

Also, you are making a rod for your own back by putting style rules inside your HTML.
 
hyper said:
I suspect it's to do with your CSS, there's no need to put form elements inside <p> elements, just format the form elements.

Check to see if you have a height for the Body or P-1 classes.

Also, you are making a rod for your own back by putting style rules inside your HTML.

Hi

Thanks. I took out the <p> </p> tags and low and behold, the page works fine now.

Thanks again.
 
To prevent the issue where the first line of the message is overwritten on the screen when the sender enters a multi-line message, you need to make a slight modification to the code.

Currently, the value of the your_message textarea is being set with value="<?php echo $yourmessage; ?>". However, the value attribute is not applicable for multi-line input fields like textarea. Instead, you should place the $yourmessage variable between the opening and closing tags of the textarea.

Here's the updated code snippet for the message textarea:
<p class="Body P-1"><span class="c-16">Message </span><textarea rows="50" cols="50" name="your_message"><?php echo $yourmessage; ?></textarea></p>

By removing the value attribute and placing <?php echo $yourmessage; ?> between the opening <textarea> and closing </textarea> tags, the textarea will display the full content of $yourmessage without any truncation or overwriting.

This change ensures that the sender can see and edit the entire message, including multiple lines and line breaks, before submitting the form.

Make sure to update this code snippet in your contactus.php file and test it to confirm that the issue is resolved and the sender can view the complete message.
 
Back
Top