Jump to content


Photo

Getting form information from $_POST


  • Please log in to reply
3 replies to this topic

#1 SCook

SCook
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts

Posted 11 March 2006 - 12:34 PM

Hi gang,

Quick question: Is there a way to determine the type of the form variable that is sent to PHP? Just as you can do:

foreach($_POST as $key => $value) to get the name and value, there must be a way to get other form info too. Or is there someplace with a better description of $_post. PHP manual is very vague here. Thanks

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 March 2006 - 12:39 PM

Quick answer: No.

Quick question: Why do you care/need to know?

Quick-and-dirty option: use logical form variable names to distinuguish input types.
Legend has it that reading the manual never killed anyone.
My site

#3 SCook

SCook
  • Members
  • PipPipPip
  • Advanced Member
  • 73 posts

Posted 11 March 2006 - 01:18 PM

I want to know because I'm doing some dynamic form creation via the database table into which the form data must be entered. Then, when the form is submitted, I'm building the query out of the names and values of the form elements, as their names match the mysql field names. The form is retty large, and if this works out, it'll save me hours of programming. I'm trying to oop the form to database process.

I could use JavaScript to create a list of types, or as you say, I could do something like this: <input type = "text" name = "t-address" > wherein I could split each $key by the dash, or whatever, and with switch case the character before it to get the type. I was just hoping there might be a built in way.

Oh, I forogot one thing. You may still be asking why I want the types, the reason is that I need to filter out the non-data elements like hidden, submit, button, reset, etc. And if the form elements contains information that needs to be entered as strings or int or decimal, I ned to know that to propertly format the query.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 11 March 2006 - 01:30 PM

.. moving this along (I hope) ..

If the 'non-data' inputs had their names identifiable, e.g. all named ignore_[input name], you could skip over them in the loop where you retrieve the $_POST array keys/values. That would remove one problem. Hidden inputs need to be handled differently as they presumably exist for some post-submission processing purpose.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users