getting child script to see the parent script's form field values?

Currently I have a php page/script and at some point in the script I have an include statement with the parameter of another php script.
So its :
"parent.php"
--------------------
<?

/*
 code
*/
include("child.php");
/*
 more code
*/
?>
When I click a button generated from the child.php script, it submits to the parent script's form element. The problem I am having is after doing so, I can see a form hidden field value in the parent  script, but the child script does not see that value. I need the child script to see that value in order to do some processing. Is there any way I can get the child script to see the parent scripts form field values?

Thanks!
mistertransistorAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Snow-StormCommented:
That is weird because when you include them they should become like one file.  Try using require instead of include to see if its messing up somewhere with inclusion.
0
waanCommented:
Could you possibly supply a little more detail, especially in relation to the parent and child scripts
0
aabbasCommented:
Make make sure, your child script does not access the hidden value withing a function. Functions have their own scope for every variable.

Therefore, you might need to use global keyword within child's function to make that hidden variable of parent script visible to child function too.

e.g.

"parent.php"
--------------------
<?
$secret = $_REQUEST["secret"];
/*
 code
*/
<input type=hidden name=secret value="Bravo!">
/*
 code
*/
include("child.php");
/*
 more code
*/
function printValue () {
  global $secret; // <--- THIS WILL MAKE THE PARENT VARIABLE VISIBLE TO CHILD.
  echo $secret;
}
/*
 more code
*/
?>

Hope, it will help.

Best of luck.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mistertransistorAuthor Commented:
Sorry for the delay in responding. Thanks a lot aabbas, using $_REQUEST["fieldname"] worked out just fine. At first I thought I just needed the parent script to set that variable as global which I did but still no dice. Then using $_REQUEST the value showed up so all is well now. Thanks again! (I wonder if setting global variables are even needed if you can just use $_REQUEST array? well another thought for another time. Thanks again!
0
aabbasCommented:
Well, Mister Transistor!

$_REQUEST["fieldname"] is used to receive the variable values by a submitted form. On the other hand, global keyword is used to make an out-of-scope variable visible to a child (sub-scope) function.

If you are not using function, then you don't need to put global there. e.g.
$a = $_REQUEST["secret"];
echo $a;

While, if you are using function then you will need to put global to access the value, otherwise it will be blank. e.g.
$a = $_REQUEST["secret"];
function b() {
  echo $a; // <== It won't work, because it will create $a with its own (new) scope.
}
function b() {
  global $a;
  echo $a; // <== It will work because it will get the value from the parent scope of $a.
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.