Parent/child forms... How does this example work?
Posted: Wed Dec 02, 2009 9:13 pm
I'm sure you guys have seen this example a ton of times, but I need to figure out how to do parent/child forms so I can call the child when a button gets hit on the parent, and stay on the child until the user exits...... I found this example, but I'm not good enough at php yet to figure out how to make it work.... Can one of you tell me what's missing or what needs to be done differently or whatever? And am I supposed to have html stuff top and bottom - is this whole bunch of php supposed to be inside an html body or something?
When I run this the display_name appears to run. BUT, stage doesn't seem to ever get set to "cheese". How come?
And at the bottom, in the else, if process_form. Isn't process_form a function? And where is it?
<?php
function display_name() {
global $PHP_SELF;
?>
<FORM TARGET="<?php echo $PHP_SELF; ?>" METHOD=GET>
Name: <INPUT TYPE=TEXT NAME="name"><BR>
<INPUT TYPE=HIDDEN NAME="stage" VALUE="cheese">
<INPUT TYPE=SUBMIT VALUE="Thanks!">
</FORM>
<?php
}
?>
<?php
function display_cheese() {
global $PHP_SELF;
global $name;
?>
<FORM TARGET="<?php echo $PHP_SELF; ?>" METHOD=GET>
Favorite Cheese: <INPUT TYPE=RADIO NAME="cheese" VALUE="brie">Very soft French Brie
<INPUT TYPE=RADIO NAME="cheese" VALUE="cheddar">Farmhouse English Cheddar
<INPUT TYPE=RADIO NAME="cheese" VALUE="mozzarella">Italian Buffalo Mozzarella
Favorite Times to Eat Cheese: <INPUT TYPE=CHECKBOX NAME="times[]" VALUE="m">Morning
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="n">Noon
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="d">Dinner
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="l">Late night
<INPUT TYPE=HIDDEN NAME="name" VALUE="<?php echo htmlspecialchars($name); ?>">
<INPUT TYPE=HIDDEN NAME="stage" VALUE="results">
<INPUT TYPE=SUBMIT VALUE="Thanks!">
</FORM>
<?php
}
?>
<?php
if (empty($stage)) { display_name(); }
elseif ($stage == 'cheese') { display_cheese(); }
else { process_form(); }
?>
When I run this the display_name appears to run. BUT, stage doesn't seem to ever get set to "cheese". How come?
And at the bottom, in the else, if process_form. Isn't process_form a function? And where is it?
<?php
function display_name() {
global $PHP_SELF;
?>
<FORM TARGET="<?php echo $PHP_SELF; ?>" METHOD=GET>
Name: <INPUT TYPE=TEXT NAME="name"><BR>
<INPUT TYPE=HIDDEN NAME="stage" VALUE="cheese">
<INPUT TYPE=SUBMIT VALUE="Thanks!">
</FORM>
<?php
}
?>
<?php
function display_cheese() {
global $PHP_SELF;
global $name;
?>
<FORM TARGET="<?php echo $PHP_SELF; ?>" METHOD=GET>
Favorite Cheese: <INPUT TYPE=RADIO NAME="cheese" VALUE="brie">Very soft French Brie
<INPUT TYPE=RADIO NAME="cheese" VALUE="cheddar">Farmhouse English Cheddar
<INPUT TYPE=RADIO NAME="cheese" VALUE="mozzarella">Italian Buffalo Mozzarella
Favorite Times to Eat Cheese: <INPUT TYPE=CHECKBOX NAME="times[]" VALUE="m">Morning
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="n">Noon
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="d">Dinner
<INPUT TYPE=CHECKBOX NAME="times[]" VALUE="l">Late night
<INPUT TYPE=HIDDEN NAME="name" VALUE="<?php echo htmlspecialchars($name); ?>">
<INPUT TYPE=HIDDEN NAME="stage" VALUE="results">
<INPUT TYPE=SUBMIT VALUE="Thanks!">
</FORM>
<?php
}
?>
<?php
if (empty($stage)) { display_name(); }
elseif ($stage == 'cheese') { display_cheese(); }
else { process_form(); }
?>