Page 1 of 1
validate form fields - remove/trim blank spaces
Posted: Mon May 09, 2011 12:54 pm
by cjkeane
hi everyone.
i'm using the following function to apply mysql_real_escape string and htmlentities to form fields. is there a way to modify it to trim white space (left and right) from form fields? i'm not quite sure how to go about doing it.
Code: Select all
<?php
function safe($value){
return mysql_real_escape_string(htmlentities($value));
}
?>
Re: validate form fields - remove/trim blank spaces
Posted: Mon May 09, 2011 1:06 pm
by greyhoundcode
You could use the
trim() function.
Code: Select all
return mysql_real_escape_string(htmlentities(trim($value)));
Re: validate form fields - remove/trim blank spaces
Posted: Mon May 09, 2011 1:10 pm
by cjkeane
thanks. i was looking at trim, but i wasn't sure if it would need to cycle through all form fields or just add the trim function to my existing function. i'll give it a try.
Re: validate form fields - remove/trim blank spaces
Posted: Mon May 09, 2011 1:36 pm
by greyhoundcode
cjkeane wrote:but i wasn't sure if it would need to cycle through all form fields or just add the trim function to my existing function.
Depending on your intentions you could of course place either your modified function or just trim by itself in a for/foreach loop, or something like that.
Re: validate form fields - remove/trim blank spaces
Posted: Mon May 09, 2011 2:10 pm
by cjkeane
i had to use a for each function with trim in order to check each field before data was posted.
thanks for the help. it got me going in the right direction.
problem solved!