Page 1 of 1

Trying to use a concatenated constant in $_POST

Posted: Mon May 07, 2007 4:27 pm
by McManCSU
I get an undefined index in this example:

Lets say that I do a print_r($_POST) and I verify that $_POST has some value:

Code: Select all

Array 
(
    [testExample] => thisIsAnExample
)
Here is the implementation:

Code: Select all

define('XYZ_TEST', 'testExample');

function One()
{
     functionTwo("XYZ");
}

function Twp($prefix)
{
    $input = $prefix . '_TEST';
    echo 'Post variable=' . $_POST[$input] . ' gives an undefined index';
}
I have tried doing things such as trimming the $input variables and stripping single and double quotes, but still nothing...

I should note that if I set up $input to be "testExample", all works fine, but since this is not using the constant properly I can't do it this way.

Thanks!

Posted: Mon May 07, 2007 4:36 pm
by volka

Code: Select all

define('XYZ_TEST', 'testExample');

function One()
{
  Two("XYZ");
}

function Two($prefix)
{
  $input = constant($prefix . '_TEST');
  echo 'Post variable=' . $_POST[$input];
}

// test
$_POST = array('testExample'=>'abc');
One();

Posted: Mon May 07, 2007 4:44 pm
by McManCSU
Awesome, thanks a lot!