frost Posted January 3, 2008 Share Posted January 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84378-solved-get-form-element-type/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2008 Share Posted January 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84378-solved-get-form-element-type/#findComment-429766 Share on other sites More sharing options...
frost Posted January 3, 2008 Author Share Posted January 3, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/84378-solved-get-form-element-type/#findComment-429768 Share on other sites More sharing options...
duclet Posted January 3, 2008 Share Posted January 3, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84378-solved-get-form-element-type/#findComment-429773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.