1

There is an example what I want to do: http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_input_type_datetime

In this example, if you change the input's name, on the right side of screen (after submitting code), you'll see the changed name. And also, as you can see there is no hidden input field to get the name of input automatically. Because I searched for some answers and they say "use an hidden input field" like in this: How to access the form's 'name' variable from PHP But I need it exactly in the w3schools.

Of course this is an .asp example but I hope there is a way for this via PHP also? Thanks in advance.

6
  • Where exactly do you see form's name on the right side? Commented Mar 6, 2014 at 11:49
  • It is the input name you see. Commented Mar 6, 2014 at 11:50
  • @Indianer ah ok sorry. I edited. But I still have my question. Thanks. Commented Mar 6, 2014 at 11:52
  • There is no way to do it as stated in the other question's answer. Commented Mar 6, 2014 at 11:52
  • @Indianer then how about the example of w3? they did it how? Thanks. Commented Mar 6, 2014 at 11:55

3 Answers 3

1

To get all input field name using post method.

you can use $GET or $REQUEST instead of $POST.

$REQUEST use with both GET and POST. In php $POST is a one type of associative array.

<?php
$temp= array();
if (isset($_POST['submit']) && !empty($_POST['submit'])) {
    foreach ($_POST as $key => $val) {
        //$key is the name you wanted, and $val is the value of that input
        $temp[] = $key;
    }
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

I tried that now and then tried print_r ($temp); but the result is nothing.
btw, i added if (isset($_POST) && !empty($_POST)) { echo "hello"; to try, and it doesn't print "hello" to screen.
ok I used GET instead of POST, and it works perfect. Thanks a lot.
0
<?php
    foreach($_POST as $key => $val) {
        print $key . " = " . $val;
     }
 ?>

Comments

-1
$_GET['bdaytime'];

using the above code.

1 Comment

I don't think this will answer the question the user has asked. Also please elaborate.

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.