Jump to content
Larry Ullman's Book Forums

Cursor Jumps (5?) Points Into Text Area Field On First Click?


Recommended Posts

I am trying to confirm entries in the form below using strlen but am stymied by a strange bug/error - in check for entries in subject and message fields

else if((strlen($_POST['subject']) == 0) || (strlen($_POST['message']) == 0)) the first condition works perfectly ($length=0) but strlen($_POST['message'] returns $messagelen=5 or more even when nothing is entered?!

When you first click in the textarea the cursor positions beyond the start point - which is probably causing the error, but why?

 

Thank you for any help.

 

 

<?php

function spamcheck($field)

{

//filter_var() sanitizes the e-mail

//address using FILTER_SANITIZE_EMAIL

$field=filter_var($field, FILTER_SANITIZE_EMAIL);

 

//filter_var() validates the e-mail

//address using FILTER_VALIDATE_EMAIL

if(filter_var($field, FILTER_VALIDATE_EMAIL))

{

return TRUE;

}

else

{

return FALSE;

}

}

 

 

 

if (isset($_POST['email']))

{//if "email" is filled out, proceed

 

//check if the email address is invalid

$mailcheck = spamcheck($_POST['email']);

if ($mailcheck==FALSE)

{

$url = htmlspecialchars($_SERVER['HTTP_REFERER']);

echo "<a href='$url'>Invalid form entry.<br><br> Please click here to return to form and retry.</a>";

}

// check for entries in subject and message fields

else if((strlen($_POST['subject']) == 0) || (strlen($_POST['message']) == 0))

{

$url = htmlspecialchars($_SERVER['HTTP_REFERER']);

$length = strlen($_POST['subject']);

$messagelen = strlen($_POST['message']);

echo "<a href='$url'>Please fill in all fields. " . $length . $messagelen . "<br><br> Please click here to return to form and retry.</a>";

}

 

else

{//send email

$email = $_POST['email'] ;

$subject = $_POST['subject'] ;

$message = $_POST['message'] ;

mail("me@example.com", "Subject: $subject",

$message, "From: $email" );

$url = htmlspecialchars($_SERVER['HTTP_REFERER']);

 

echo "Thank you for using our mail form";

 

echo "<a href='$url'>Click here to return</a>";

}

}

else

{//if "email" is not filled out, display the form

echo "<p><b>If you have any questions and wish to contact us,<br /> please fill in the form below.</b></p><br>

 

<form method='post' action='formpage.php'>

<fieldset><legend>Your Contact Information</legend>

Email: <input name='email' type='text' tabindex='1'><br>

Subject: <input name='subject' type='text' tabindex='2'><br>

Message:<br>

<textarea name='message' rows='7' cols='40' tabindex='3'>

</textarea><br>

<input type='submit' id='submit' tabindex='4'>

</fieldset>

</form>";

}

?>

Link to post
Share on other sites

There is likely some whitespace between the textarea start tag and the textarea end tag. That will be interpreted by the browser as whitespace that you actually want to enter within the textarea.

Try putting your textarea tags together as follows:

<textarea name='message' rows='7' cols='40' tabindex='3'></textarea><br>
  • Upvote 1
Link to post
Share on other sites

Okay all that you have said in this and 'Trying To Return To Previous Page From A Form' has worked perfectlybut...

 

below is the source code from the formpage being 'posted' to itself. Every thing looks as though it should be fine but the value of the message field 'dddd' is not displayed.

 

Have I hit the edge again - I'm really not doing very well with this message field!

 

 

<form method='post' action='formpage.php?urlinform=http://localhost:8888/Any_root/anotherpage.html&email=&subject=sssss&message=dddd'>

<fieldset><legend>Your Contact Information</legend>

Email: <input name='email' type='text' value='' tabindex='1'><br>

Subject: <input name='subject' type='text' value='sssss' tabindex='2'><br>

Message:<br>

<textarea name='message' rows='7' cols='40' value='dddd' tabindex='3'></textarea><br>

<input type='hidden' name='urlinform' value='http://localhost:8888/Any_root/anotherpage.html'>

<input type='submit' id='submit' tabindex='4'>

</fieldset>

</form>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...