[Resolved] Unwanted elimination of zero in POST value
Hello all.
I have a form page with a field for Zip Codes:
Code:
<input type="text" name="customer_zip">
Now, some Zip Codes, in New Jersey in particular, begin with a zero. As in 01234.
When this field gets posted, the zero in the front gets trimmed.
I don't know if it's the operating system (Win 2k Server) or PHP.
Does anyone know how I can rectify this situation?
Many thanks.
Re: Unwanted elimination of zero in POST value
i think its thge operating system cause wenever i wanna trim something i gotta use the trim(); function
Re: Unwanted elimination of zero in POST value
could i see an example of how you are using it?.... cuz it sounds kinda funky to me.
Re: Unwanted elimination of zero in POST value
Re: Unwanted elimination of zero in POST value
Re: Unwanted elimination of zero in POST value
Quote:
Originally Posted by solitario
Hello all.
I have a form page with a field for Zip Codes:
Code:
<input type="text" name="customer_zip">
Now, some Zip Codes, in New Jersey in particular, begin with a zero. As in 01234.
When this field gets posted, the zero in the front gets trimmed.
I don't know if it's the operating system (Win 2k Server) or PHP.
Does anyone know how I can rectify this situation?
Many thanks.
All post variables should be sent to the PHP script as strings. So unless an operation in your script has cast the data type of the variable to a numeric type, the zero should remain.
To force a string type when carrying out operations on the variable you should explicitly cast it each time:
Code:
$customer_zip = (string) $_POST['customer_zip'];
Re: Unwanted elimination of zero in POST value
That did it, visualAd. Thanks.