Page 1 of 1

ltrim() and stripslashes() are not consistent

Posted: Wed May 31, 2006 10:01 am
by KimberCat
Hi,

I have a php form that requests info from the user - some text boxes and a text area. The user can use an edit button to go back and edit his/her info before submitting the final form. Problem is that ltrim() does not work on all of the variables. I am still getting leading white spaces on some of the variables, while others aren't when the user uses the edit button to go back. I have checked my code carefully. Same thing going on with the stripslashes(). In some sections, it removes the "/" in front of apostrophes and in others, it doesn't.

Any suggestions?
Thanks, Kimber

Posted: Wed May 31, 2006 10:09 am
by feyd
post your code.

ltrim() & stripslashes() not being consistent

Posted: Wed May 31, 2006 10:36 am
by KimberCat

Code: Select all

<input type="hidden" name="firstName" value=" <? $firstName = ltrim($firstName); print stripslashes($firstName) ?> ">
<input type="hidden" name="lastName" value="<? $lastName = ltrim($lastName); print stripslashes($lastName) ?> ">

<strong><div style="margin-right: 150px"><? $message=ltrim($message);  print stripslashes($message); ?></div></strong>
In the above snippet of code, when the user clicks on the edit button and goes back to edit the form, the last name does NOT get any leading white space inserted before it in the text box, but the first name does.

The message gets indented and broken up over numerous lines when printed out in the text area, if the user goes back to edit their info. It is also escaping any apostrophes that the user might enter in their message. If the user goes back more than once, it is a real mess. However going from the form to the confirm screen, it does NOT escape anything and behaves quite nicely. My problems are going backward to edit the original info. AAUGH.

Any help would be greatly appreciated.

Thanks, Kimber

Posted: Wed May 31, 2006 11:18 am
by feyd
the value of firstName has space around the printed text.

As for the "textarea" it's hard to say since you didn't post more code..

leading spaces & escaped apostrophes

Posted: Wed May 31, 2006 12:49 pm
by penpaper
Thanks for pointing out the spaces in the code. They are gone now.

The code used for the textarea in the file that the user posts to an email:

Code: Select all

<strong><div style="margin-right: 150px"><? $message=ltrim($message);  
	$message=htmlspecialchars($message, ENT_QUOTES); print stripslashes($message); ?></div></strong>
This code makes for very pretty stuff when printed to screen. However, the spaces (looks like multiple tabs and hard breaks) show up when printed in a textarea.

Code: Select all

<textarea id="message" name="message" wrap="hard" cols=70 
rows=10 width="120" onKeyDown="textCounter(this.form.message,this.form.remLen,480);" 
onKeyUp="textCounter(this.form.message,this.form.remLen,480);">
			<?php   $message = ltrim($message); print stripslashes($message); ?></textarea>
When the user is satisfied with their input the form is submitted to an email which is great except for the spaces and the ENT_QUOTES prints out the ' where the apostrophe would have been and the escape backslash is there also?!????.

thanks for your help! lauren

Posted: Thu Jun 01, 2006 11:49 am
by penpaper
OK! I figured it out. I had spaces in my coding again. I now know about spaces in coding. A valuable lesson that came to me way too slowly. Thank you for your patients.

lauren