Obtaining form input types in php
Is there a php equivalent to some开发者_StackOverflowthing like this jquery:
var allInputs = $(":input"); allInputs.attr('type');
I need to retrieve the types from each of the post variables sent to a php script but I want to do it without using javascript and/or jquery, I guess it would also be nice to get the other attributes as well (id, class etc). Perhaps I have missed something but I have tried to find the answer to this on the internet in search engines etc and can't even find another question similar to this one!
Thanks for any help and advice.
There is no way to do this without passing the types from jquery or javascript. All php knows is that some strings are coming in.
You can do something like this:
$.post('blah.php',{
var1: 'test',
var1Type: 'text'
...
});
You're pretty confused, PHP is a server side language, any value in the $_POST
array is just a value (precisely a string). PHP doesn't have any idea of the input type, it's just an HTTP request with some data in its body.
To be clearer, this is what your webserver sees when you're doing a post request:
Name=Jonathan+Doe&Age=23&Formula=a+%2B+b+%3D%3D+13%25%21
PHP module reinterpret that input as key-values pairs, nothing more.
Everything is sent as a string. You have to know what are you using for and what types sent variables are and validate user input data.
精彩评论