Pass Numeric Values From Form

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
edziffel
Forum Newbie
Posts: 9
Joined: Wed Jul 13, 2011 6:32 am

Pass Numeric Values From Form

Post by edziffel »

Need to pass numeric values from user input in dynamically created drop down lists which are then posted. Because they are dynamically generated, they can not be set to a session variable before use. From what I can tell you can only pass non-numeric data via post. I need to be able to pass numeric strings i.e. (9,2) think defining length of say a DECIMAL in a MySQL column, (15, 5, xxx, ..., n) as well as just (n).

What are my options for this?
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Pass Numeric Values From Form

Post by flying_circus »

Correct, any post, get, or cookie data transmitted over HTTP will be a string.

However, if you are passing the data through a POST, you can cast the data to the type that you want before say, inserting into a database.

I dont understand this comment, it sounds like a conflicting ideology:
edziffel wrote:I need to be able to pass numeric strings i.e. (9,2)
a numeric string is just a string as far as I am concerned.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Pass Numeric Values From Form

Post by social_experiment »

The Manual wrote:Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part.
You can also use is_numeric() to see if value received from G,P or C (get, post or cookie) is indeed a numeric value.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: Pass Numeric Values From Form

Post by flying_circus »

social_experiment wrote:
The Manual wrote:Numeric strings consist of optional sign, any number of digits, optional decimal part and optional exponential part.
Huh, well I learned something new :)
Post Reply