Jump to content

Recommended Posts

Hi everyone, I'm pretty new to PHP, just learning some of the basics. I hope this question doesn't sound stupid if it's been asked a thousand times before. Here goes.

 

I am writing a script called dslhpp.php. It has a few different parts that generate html for a webform to be used by my collegues.

One section displays a 'start' page using an 'if' statement when an option has not yet been clicked by a radio button on the form.

Once one of the radio options have been selected and the form is processed using the 'POST' method, another form is displayed for the user to fill in text areas. The user can then click another button to submit the form again as 'POST'. The problem is that variables being set in this section are not passed to the script when being submitted again, also via the 'POST' method. I'm not sure if that is really explaining my situation, I may need to show the basic structure of my script later on.

OK, here is what I'm trying to do, forgive my green-ness.

 

<?php
$option = $_POST['option'];

if ((condition a) && (condition b)) {

echo "a whole bunch of html to display a form";
... <form action=\"dslhpp.php\" method=\"post\">"; .... 
if ($option = 'a') {
etc etc
$opt = 1;
}

if ($option = 'b') {
etc etc
$opt = 2;
}

if ($option = 'c') {
etc etc
$opt = 3;
}
}

if ((condition c) && (condition d)) {

I need variable from the above section ($opt) to carry through to here.

}

etc

?>

so this is just one php file that controls the various stages of a webform. 

this script runs on an OpenBSD 4.2 webserver with apache. 

thnx


???

 

ok here goes. may seem a bit strange but that's because I've deleted a lot of info that would tell you all who I work for, haha.

 

I tried some stuff with $_SESSION but, still no luck. I may just have to resort to the hidden input method, but would prefer to do this properly :)

 


<?php
session_start();

$option = $_POST['option'];
$abctn = $_POST['abctn'];
$email = $_POST['email'];

if (($option != '') && ($abctn == '')) {
 echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">

<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head>
<title>something something</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<style type=\"text/css\">
not important here; took it out.
</style></head>
<body>
<form action=\"dslhpp.php\" method=\"post\">";
echo "<div id=\"content\"><h1><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td>
<a href=\"../templates.php\">templates</a></td><td align=\"right\">blah blah <abbr title=\"Digital Subscriber Line\">DSL</abbr> blah</td></tr></table></h1></div>";


echo "<div id=\"blurb\">";	

if ($option == 'opt1') {
echo "<h4>Option 1.</h4><h4>blah blah.</h4>";
$_SESSION['opt'] = 1;
/*$opt = 1;*/	
}

if ($option == 'opt2') {
echo "<h4>Option 2.</h4>";

$_SESSION['opt'] = 2;
/*$opt = 2;*/
}

if ($option == 'opt3') {
echo "<h4>Option 3. </h4>";

$_SESSION['opt'] = 3;
/*$opt = 3;*/
}

if ($option == 'opt4') {
echo "<h4>Option 4. </h4>";

$_SESSION['opt'] = 4;
/*$opt = 4;*/
}
if (($option == 'opt1') || ($option == 'opt2')) {
echo " .....";
} 
echo ".....";
echo "<input type=\"radio\" name=\"advsdcon\" value=\"Yes\"> YES <input type=\"radio\" name=\"advsdcon\" value=\"No\"> NO</div>";

echo "</div>";
echo "<div id=\"blurb2\"><h3>REQUIRED Customer Information</h3>";
echo "<h4>WORK CONTACT NUMBER:<input type=\"text\" name=\"worktn\"></h4>";  
echo "<h4>CELL CONTACT NUMBER:<input type=\"text\" name=\"celltn\"></h4>";
echo "<h4>ASSIGNED OR TEMP PHONE NUMBER: <input type=\"text\" name=\"abctn\"></h4>";

if ($option != 'opt1') {
echo "<h4>LANDLINE PHONE NUMBER:<input type=\"text\" name=\"hometn\"></h4>";
echo "<h4>LOCAL PROVIDER: <input type=\"text\" name=\"lec\"></h4>";
echo "<h4>(If no ....)CIRCUIT NUMBER: <input type=\"text\" name=\"ctnum\"></h4>";
}

echo "<h4>EMAIL ADDRESS:<input type=\"text\" name=\"email\"></h4>";
echo "<h4>BEST TIME TO CONTACT:<input type=\"text\" name=\"besttime\"></h4>";
	echo "<h4>Full Mailing Address (from Phone Bill):</h4>";
echo "<textarea cols=\"70\" rows=\"6\" name=\"address\"></textarea></div>";
echo "<div id =\"blurb3\"><h4>High Speed Modem</h4>";
echo "<input type=\"radio\" name=\"modem\" value=\"Own\"> OWN <input type=\"radio\" name=\"modem\" value=\"Rent\"> RENT <input type=\"radio\" name=\"modem\" value=\"Purchase\"> PURCHASE<br/>";
echo "<h4>[iF OWN] Modem Make <input type=\"text\" name=\"make\"> and Model Number <input type=\"text\" name=\"model\"></h4></div>";
echo "<div id=\"blurb4\"><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td><input type=\"submit\" value=\"Process\"><input type=\"reset\"></td><td align=\"right\">";
print "<h4>Create & Close</h4></td></tr></table></div>";

}

if (($email != '') && ($abctn != '')) {

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  	\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">

<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head>
<title>more stuff</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />";
echo "</head><body>hello world";
echo $_SESSION['opt'];
if ($_SESSION['opt'] == 1) {
echo "<h4>Option 1. </h4>";
}

if ($opt == 2) {
echo "<h4>Option 2. </h4>";
}

if ($opt == 3) {
echo "<h4>Option 3. </h4>";
}

if ($opt == 4) {
echo "....";
}

echo "</body></html>";
}


elseif ($option == '') {

echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">
<head>
<title>....</title>
<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
<link type=\"text/css\" rel=\"stylesheet\" href=\"style.css\" />
</head>
<body>";
echo "<form action=\"dslhpp.php\" method=\"post\">";
echo "<div id=\"content\">";
echo "<h1><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td>
<a href=\"../templates.php\">templates</a></td>";
echo "<td align=\"right\">stuff</td></tr></table></h1>";
echo "<h2><table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\"><tr><td align=\"left\"><input type=\"submit\" value=\"GO!\"></td><td align=\"right\">WHICH OPTION APPLIES TO YOUR CUSTOMER?</td></tr></table></h2></div>";

echo "<div id=\"blurb\"><h4>Dry Loop<input type=\"radio\" name=\"option\" value=\"opt1\"></h4></div>";

echo "<div id=\"blurb2\"><h4>Reg DSL, Then Dry Loop<input type=\"radio\" name=\"option\" value=\"opt2\"></h4>.....</div>";

echo "<div id=\"blurb3\"><h4>REG DSL<input type=\"radio\" name=\"option\" value=\"opt3\"></h4>This customer has a Landline currently in their home and will be keeping it. </div>";

echo "<div id=\"blurb4\"><h4>REG DSL with 2 or More Landlines<input type=\"radio\" name=\"option\" value=\"opt4\"></h4></div>";

        }
?>
</body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.