Jump to content

dynamic $_POST


dcole.ath.cx
 Share

Recommended Posts

umm... dynamic $_POST...I'm trying to get the post from another page except I don't kow what the names of the things are... so I can't go $_POST['blah']. I have to open a file and get a list of names, then load all the names from the other page and see if they equal 1 or 0.so I need a $_POST_EVERYTHING_THE_FORM_HAS() or do a dynamic way.

Link to comment
Share on other sites

use a foreach statement like this:

<?php  foreach ($_POST as $key => $value){    echo "  <tr><td>";    echo htmlspecialchars($key,ENT_QUOTES);    echo "</td><td>";    echo htmlspecialchars($value,ENT_QUOTES);    echo "</td></tr>";  }?>

no matter what you send it, this code will echo it all. (post-echo)LG

Edited by Little Goat
Link to comment
Share on other sites

You can use this function to bring all request variables into the global scope:http://www.php.net/manual/en/function.impo...t-variables.phpOnce you do that, you would have to use 'variable variables' to refer to the individual request variables:

inport_request_variables("p", "varprefix_");$varname = "varprefix_" . $fileinfo[0];echo "the value of {$varname} is {$$varname}"; //note the double $ signs

More on variable variables:http://www.php.net/manual/en/language.variables.variable.phpHowever, your example should still work. You should also be able to do this:

$varname = $fileinfo[0];echo $_POST[$varname];

If you are getting an array index error, you could try changing the error reporting in php.ini to not report those errors (the value would just be ""), or you can also check to see if the value has been set before using it:

$varname = $fileinfo[0];if (isset($_POST[$varname])){  echo $_POST[$varname];}

More on the isset function:http://www.php.net/manual/en/function.isset.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...