3

This may be asking a lot, but I am looking for a way to detect the attributes in some of my form input fields.

For example:

<input type="text" name="fieldone" id="fieldone" value="[email protected]" />

I can simply use a php foreach loop to get the key => value information.

<?php
$querystring = "";
if ($_POST){  $kv = array();  
  foreach ($_POST as $key => $value){ $querystring .= "$key=$value<br>"; } 
}
?>

And this helps with mediocre debugging reasons.

However, this only detects the name and value of the form field. How do I detect the "id" attribute, or any custom attributes I may add.

Is there a way to detect/display the attributes of POST variables? Or does php stop at the name/value?

2
  • @user271619 I think there is no such way as getting the id, as long as you don't pass it yourself as a POST variable. Commented Feb 12, 2011 at 0:52
  • sounds like you want to be debugging the HTML and not the php. If you want to debug the HTML then you can just view the source, or use developer tools that come with most browsers. Commented Feb 12, 2011 at 1:06

3 Answers 3

4

Only Name and value are senet to the server. ID and other attributes are not sent at all (why would they).

BTW: You'll want to use print_r($_POST); or var_dump($_POST); instead of your loop.

Sign up to request clarification or add additional context in comments.

1 Comment

@Downvoter: Just edited it to actually answer the question.. so you can remove your downvote
2

Nothing except the name and value are sent over HTTP.

You'll need to use some JavaScript pre-processing for that.

For example, on form submit, you could use JavaScript to store all the attributes with the name, but this will be messy.

Comments

0

When a form is submitted, only the name and value fields are used. The other fields are only used client side (inside the browser) and not returned to the server.

Comments

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.