0
votes

Hi I am sending a form through post to a php file that I have made. I have been able to use $_POST["name"] to get the vales of input fields of type text/password,/etc but now I would like to also get their 'type'. So in my variable $car = $_POST["car"]; will store the value, I would like $carInputType to store the inputs type. So if in the form the person chose Mazda in a checkbox, I would like the $carInputType to hold 'checkbox' the type.

I hope I explained this well I think this could be useful for many people to learn. I have been looking around but I have not found ANYTHING to answer this. I have tried:

$radio = $_POST["fname[type]"];
$radio = $_POST["fname[type=]"];

A bit of my form is as follows:

<form id="ajax-form" onsubmit="return false;">
<div><label for="uname">Username <em>*</em></label> <input id="uname"     type="text" name="uname" value=""  /><p class='note' id = "userNameID"></p>        </div>
</form>

Any help would be greatly appreciated. Thank you for reviewing my post.

1
what is form html code?ashkufaraz
your question is not clearashkufaraz
It is though, I posted my form to my php page and can easily grab the value of it using $name = $_POST["uname"]; Now I would just like to store the type not the valueJonathan Michael Bellfontaine
The <form> sets type ... method="get" or method="post". If you are confused set a hidden input and check if(isset($_GET['hidden)) {... or if(isset($_POST['hidden)) {Brian
That is not what I mean at all..please read the entire post, it is fairly straight forward what I am trying to do, I gave examplesJonathan Michael Bellfontaine

1 Answers

3
votes

You can't do this with only PHP. You would use JavaScript or jquery to build the post data as you need it.

var data =    $('#myForm').serializeArray();    
data.push({
    name: 'elementName', 
    value: 'elementValue',
    Type: 'element type'
}); 
$.post("page.php", data);