Jump to content

[SOLVED] Get form element type?


frost

Recommended Posts

Is it possible to get the form element type when posting a form?

 

For example if I have a form that has one text field and 1 radio button and I post it can PHP tell me which field was the text and which was the radio button?

 

Thanks.

Link to comment
Share on other sites

The names and values of the form fields are all that php receives and when check boxes and radio buttons are not selected/checked, the variable with their name is not even set.

 

Since the form code is yours, you know the names and can write php code that matches.

 

If you are creating dynamically generated form fields, you would need to use field names that indicate what type they were. If you have more than one field of a type, using an array makes it easier to iterate over all the values in php code using a foreach() loop.

 

If this does not answer your question, you would need to provide a specific example of what you are trying to do.

Link to comment
Share on other sites

Right, I have a loop:

 

foreach ($HTTP_POST_VARS as $name => $value)

 

This gives me the name of the field and the value inputed but it does not tell me the fleld TYPE, if the field is a text or checkbox or radio button.

 

I hope that makes sense?

Link to comment
Share on other sites

As the previous poster mentioned, PHP doesn't get the type of the input, only the name and the value. If you want to have the type, you will need to provide it to PHP via various methods. One way is to let PHP know with a hidden input text field that tells PHP the type of the field. Another way is to append or prepend the field type to the name, then extract it when you receive it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.