...

View Full Version : If complete, contract the div



thesavior
01-01-2006, 07:58 PM
I want to have a script that does something like this:

-----------------------------------------------------
-----------------Step 1 -----------------------------
-----------------------------------------------------
please do blah blah blah, php is now checking for
blah blah blah.

-----------------------------------------------------
-----------------Step 2 -----------------------------
-----------------------------------------------------

-----------------------------------------------------
-----------------Step 3 -----------------------------
-----------------------------------------------------

-----------------------------------------------------
-----------------Step 4 -----------------------------
-----------------------------------------------------

If step 1 is finished, and php is happy with whatever the code is in it, then contract step 1, and show step 2. How can i do this?

degsy
01-01-2006, 08:48 PM
On a basic level you can use If/Else to calculate what has been submitted and tell the form at what point it is upto.



<?php
session_start();

$step = 1;
$submit = $_POST['Submit'];

if(isset($submit)){

if($submit == 'step1'){
if(empty($_POST['name'])){
$err = "Please fill in your name";
$step = 1;
}
else{
$_SESSION['name'] = $_POST['name'];
$step = 2;
}
}
if($submit == 'step2'){
if(empty($_POST['age'])){
$err = "Please fill in your age";
$step = 2;
}
else{
$_SESSION['age'] = $_POST['age'];
$step = 3;
}
}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<div>
<h3>Step1</h3>
<?php
if($step == 1){
if(isset($err)){
echo $err;
}
?>
<form id="form1" name="form1" method="post" action="">
<label>
Name:
<input type="text" name="name" />
</label>
<label>
<input type="submit" name="Submit" value="step1" />
</label>
<br />
</form>
<?php
}
else{
echo "Step1 complete";
}
?>
</div>
<br />
<div>
<h3>Step2</h3>
<?php
if($step == 2){
if(isset($err)){
echo $err;
}
?>
Thankyou <?=$_SESSION['name']?>. Please fill in your age.
<form id="form2" name="form2" method="post" action="">
<label>Age:
<input type="text" name="age" />
</label>
<label>
<input type="submit" name="Submit" value="step2" />
</label>
</form>
<?php
}
else{
if($step == 3){
echo "Step2 complete";
}
else{
echo "Please complete Step1";
}
}
?>
</div>

<?php
if($step == 3){
?>
<br />
<div>
<h3>Results</h3>
<p>
<?php
echo 'Your name: ',
$_SESSION['name'],
'<br />Your age: ',
$_SESSION['age'];
}
?>
</p>
</div>
</body>
</html>


You can make it look fancier using CSS and display or visibility and contractible headers.

thesavior
01-01-2006, 10:27 PM
let me rephrase my first post. Lets say i add a submit button, and it will now go through and check the open step, that should make it easier.

Also, the script you gave me, i don't see how i could use that for my means.

Velox Letum
01-01-2006, 10:50 PM
This is a simple problem. Figure out how to lay out your "steps" in HTML using CSS to control of they are open or closed, then use PHP to control which CSS class is used on each div. It isn't that hard.

thesavior
01-01-2006, 11:02 PM
here is the example of what i want it to look like with html and css.

http://www.lonelylizard.com/~eli/test/tms/install/install1.php

thesavior
01-02-2006, 05:30 AM
there has got to be an easier way to do what i want then what degsy posted.

I think Velox's would work, all though im not sure exactly what he means. Can someone post an example for me to look at?

thesavior
01-08-2006, 03:15 AM
*bump*

thesavior
01-10-2006, 04:38 PM
*bump*

Velox Letum
01-10-2006, 06:54 PM
Its simple. Make a mockup of the setup before hand using just HTML so you can perfect CSS styles for closed steps and open steps, then use PHP to echo out the correct class names for each div, so if it's step two it echo's out the closed CSS class for all but step two's div. Not hard.

thesavior
01-10-2006, 09:27 PM
ok, what is the php code that i use however to control the styles used?

Velox Letum
01-10-2006, 09:54 PM
It would appear that all you need to do is echo out the correct information in the right places...

<?php
// Other stuff
?>

<div class="titlefor">
Step 1</div>
<?php
if ($step == 1) {
include 'step1.php';
}
?>
<br />

<div class="titlefor">
Step 2</div>
<?php
if ($step == 2) {
include 'step2.php';
}
?>
<br />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum