Tutorial :Find out what type of form field was used to enter info in a form with PHP


Using PHP; is there a way to check what type of form field was used to enter info in a form.

For example: was it submitted via a list/menu, radio button, text field, textarea, or checkbox.

I have this info stored in the database; but I'm trying to see if there is a way to do it without querying the database or using hidden form fields to pass the field type. Basically is there a function that already does this?


I don't know of one though I'm sure someone else might pop up with an answer. But if the forms in question are of your own design you could name the inputs as checkbox_ or textarea_ prepended to your normal name. Then parse them on the form processing side.


The data entered into a form will be submitted as a set of key:value pairs only.

With standard HTML form elements only there is no way of telling what type of form field was used to gather a particular value.


Only name/value pairs are passed through the Post data, so you would need to mark it in the field name to give your server script a hint of what it is. You could do this with a prefix/postfix. Depending on where you are in your project, you may want to look into using a framework and taking advantage of the advanced form handling options that they can give you.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »