Displaying a form from a nested function.
Posted: Thu Jul 17, 2008 2:29 pm
I’m having trouble displaying a form from within a nested function – maybe somebody’s faced this before.
Here’s the setup:
I have an initial starting page – let’s call it A.php.
Pathname for A.php: Localhost/A.php
A.php contains a form that extracts input from the client then processes it by calling a function – b(). b() kicks off some processing which nests down to a function f(). Once at f(), we then want to go back to the client and ask for some more input, before branching:
function f() {
Require_once ‘path_to_G/G.php’;
$result = prompt_user($options);
If ($result == ‘a’) {
// do A
} else {
// do B
}
} // end f()
prompt_user() is in G.php:
<?php
function prompt_user($options) {
?>
HTML form here
<?php
if (isset($_POST[‘submit’])) {
// Capture users’ selection
$response = $_POST[‘choice’];
return $response;
}
>?
If I try to execute this code, prompt_user() simply returns a null value without waiting for a response from the client. The form is displayed (the URI shows ‘localhost/A.php’) but when the “Submit” button is pushed, the client browser loads ‘path_to_G/G.php’ and quits.
How do I get my form displayed, and capture what’s POSTed without prompt_user() returning prematurely?
I’ve also tried first redirecting to G.php before trying to throw up the form, but then the program stack is lost and I can’t get the $response back to the calling function. (f()) Any ideas?
Here’s the setup:
I have an initial starting page – let’s call it A.php.
Pathname for A.php: Localhost/A.php
A.php contains a form that extracts input from the client then processes it by calling a function – b(). b() kicks off some processing which nests down to a function f(). Once at f(), we then want to go back to the client and ask for some more input, before branching:
Code: Select all
Require_once ‘path_to_G/G.php’;
$result = prompt_user($options);
If ($result == ‘a’) {
// do A
} else {
// do B
}
} // end f()
Code: Select all
Code: Select all
function prompt_user($options) {
?>
HTML form here
<?php
if (isset($_POST[‘submit’])) {
// Capture users’ selection
$response = $_POST[‘choice’];
return $response;
}
>?
Code: Select all
How do I get my form displayed, and capture what’s POSTed without prompt_user() returning prematurely?
I’ve also tried first redirecting to G.php before trying to throw up the form, but then the program stack is lost and I can’t get the $response back to the calling function. (f()) Any ideas?