0

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.

5
  • what is form html code? Commented Mar 29, 2015 at 6:01
  • your question is not clear Commented Mar 29, 2015 at 6:11
  • 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 value Commented Mar 29, 2015 at 6:24
  • 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)) { Commented Mar 29, 2015 at 6:41
  • 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 examples Commented Mar 29, 2015 at 6:44

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

2 Comments

If I can get the value easily through post I do not see why I cannot get the type
Because post transmits only the name value pairs, not the element type. If you look at the post data the type is not sent. See the following W3 spec. w3.org/TR/html401/interact/forms.html#h-17.13.3.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.