|  | Posted by Mason Barge on 06/13/73 12:00 
"Good Man" <heyho@letsgo.com> wrote in message news:Xns9A267B2AAC6C7sonicyouth@216.196.97.131...
 > "Mason Barge" <masonbarge@comcast.net> wrote in
 > news:NfidnfLSQ8PTQhHanZ2dnUVZ_hOdnZ2d@comcast.com:
 >
 >> I have a standard POST form consisting of two types of input: text
 >> input and textarea.  The form downloads current settings from a mysql
 >> database.  The user can update the information by modifying the text
 >> and clicking a standard "submit" button.
 >>
 >> MAIN PROBLEM:
 >>
 >> My problem is that the information transmitted to the formhandler
 >> apparently has some sort of whitespace added to it.  If I simply use
 >> trim() on the POST variable, it fails the regex.
 >
 > No it doesn't.  You are confused about what a post variable is.  You
 > can't change what's been $_POSTed, but you can certainly ASSIGN the
 > value to your own variable and change *that*.
 >
 >> If I convert to POST
 >> variable to a single variable and use trim(), it solves the problem.
 >
 > As explained above.
 >
 >
 >> I can just convert and trim every variable, but it would be a lot
 >> cleaner to trim the entire POST array with a foreach(). Plus, I'd much
 >> rather understand the problem.  In other words:
 >>
 >> This code works:
 >> $zip=trim($_POST['zip']);
 >> if (preg_match("/^[\d]{5}/", $zip)) {
 >>     $update.=" zip='$zip',";
 >> } else {
 >> error_alert('Zip code must be exactly 5 digits with no other
 >> characters. '); }
 >>
 >> This code throws a regex rejection:
 >>
 >> $_POST['zip']=trim($_POST['zip']);
 >
 > as hinted at above - what are you doing here?  why are you trying to
 > *set* a $_POST variable, which has a very specific meaning?  Why are you
 > using this code at all, as opposed to the code above which does what you
 > want in the correct way???
 >
 > Are you trying to trim the $_POST elements in one fail swoop?  Well you
 > can either use array_map to apply a trim-type function to the $_POST
 > array, but be aware that it will mess up any $_POST elements which are
 > arrays themselves (unless you use one of the user contributions on the
 > manual page). Personally, I specifically trim every $_POST'ed element.
 >
 
 Thanks for the response, it was very helpful.
  Navigation: [Reply to this message] |