Jump to content

Archived

This topic is now archived and is closed to further replies.

SCook

Getting form information from $_POST

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
.. 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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.