|
Posted by Mason Barge on 10/16/70 12:00
"Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message
news:op.t4zefq1y5bnjuv@metallium.lan...
On Tue, 15 Jan 2008 17:28:59 +0100, Mason Barge <masonbarge@comcast.net>
wrote:
> 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. If I convert to POST
> variable to a single variable and use trim(), it solves the problem.
>
> This code throws a regex rejection:
>
> $_POST['zip']=trim($_POST['zip']);
> if (preg_match("/^[\d]{5}/", $_Post['zip'])) {
$_Post != $_Post
As soon as you've fixed that, this would work, but it is not
recommendable. Having a clear view of what your user actually submitted,
and how you've handled/altered the data after that will save you lots of
debugging time.
And just on a side note: shouldn't it be "/^[\d]{5}$/" ? The regex now
will consider '12345and then some arbitrary text or characters' valid...
Yes, of course it should. I got sloppy because the input form is maximum
size 5.
> SECONDARY PROBLEM
>
> Of course, my real problem is how the whitespace gets in there in the
> first place. Or more accurately, why the regex would reject information
> from the database. In the case of "$zip", the field is VARCHAR(5).
>
> Here's the form entry:
> <input type="text" name="zip" size="5" maxlength="5"
> value="<?php if(isset($_POST['submit'])) {
> echo $_POST['zip'];
> } else {
> echo $zip;
> } ?>
> " />
Here is is. You have whitespace between '?>' and '" />', which will
probably translate itself to a space in the field in HTML context.
Use:' } ?>" />'
--
Rik Wasmus
That's so dumb I can't even get embarrassed. Even worse, I've fixed the
exact problem before, LOL. Thanks for pointing it out.
I think I need a nap.
[Back to original message]
|