Page 1 of 1

keeping the info

Posted: Sun Jul 18, 2004 11:58 pm
by AlbinoJellyfish
I built a form, and if a username is already taken, it sends you back to the form. Is there a way to keep the information on the form?

Code: Select all

<?php
session_start();
header("Cache-control: private"); 
?>
<html>
<head><title>Confirm your order</title>
<SCRIPT LANGUAGE="JavaScript">
function goToURL1() { window.location = "confirmation.php"; }
function goToURL2() { window.location = "form.php"; }
</script><LINK href="generic.css" 
type=text/css rel=stylesheet>
<style>
<!--
BODY{
scrollbar-face-color:#4b4b4b;
scrollbar-arrow-color:#ff6600;
scrollbar-track-color:#4b4b4b;
scrollbar-shadow-color:#363636;
scrollbar-highlight-color:#4b4b4b;
scrollbar-3dlight-color:#919191;
scrollbar-darkshadow-Color:#363636;
}
-->
</style></head>
<body BGCOLOR=#4b4b4b><?
$name=$_POST['name'];
$username=$_POST['username'];
$email=$_POST['email'];
$pass=$_POST['password'];
$pass1=$_POST['password1'];
$design=$_POST['design'];
$package=$_POST['package'];
$rollovers=$_POST['rollovers'];
$news=$_POST['news'];
$flash=$_POST['flash'];
$payment=$_POST['select'];
$cost = 0;
$uname = "0";
$db = mysql_connect("localhost","bbb","da2"); 
mysql_select_db("sevengfx_com_-_hosted" , $db) or die("Couldn't open $db: ".mysql_error()); 
$sql = "SELECT * FROM support_users";
$result=mysql_query($sql); 
while ($row = mysql_fetch_array($result)){ 
if ($username == $row['username']){
while ($uname != "1"){
echo '<font color="red">That username is already taken.  Please create a new one.</font>';
$_SESSION['used'] = "1";
include 'form.php';
$uname = "1";
		}
	} }
if ($uname == "1"){
echo '<br>';
} else {
$count = strlen($pass);
 
if ($package != "PSD"){$psd = "No";
} else {$pack = "PSD Only.";
$cost = ($cost + 10);}
if ($package != "twopage"){$twopage = "No";
} else {$pack = "Two Page Basic";
$cost = ($cost + 20);}
if ($package != "Fullsite"){$fullsite = "No";
} else { $pack = "Full site Design";
$cost = ($cost + 30);}
if ($rollovers != "Yes"){$rollovers = "No";}
if ($news != "Yes"){$news = "No";
} else {$cost = ($cost + 5);}
if ($flash != "Yes"){$flash = "No";
} else {$cost = ($cost + 5);}
if ($count < 6){ echo '<font color="red">Passwords need to be at least 6 characters long.</font>';
include 'form.php';} elseif ($count > 12){ echo '<font color="red">Passwords need to be less than 13 characters long.</font>';
include 'form.php';} else {
$pass2 = md5($pass);
$pass3 = md5($pass1);
$regex =
  '^'.
  '[_a-z0-9-]+'.        
  '(\.[_a-z0-9-]+)*'.  
  '@'.                  
  '[a-z0-9-]+'.       
  '(\.[a-z0-9-]{2,})+'. 
  '$';
if (eregi($regex, $email)){
if (($pass2 == $pass3) AND ($username != "") AND ($package != "")){
$info = 'Name: '.$name.'<br>Username is : '.$username.'<br> Email is : '.$email.'<br>Package: '.$pack.'<br> Rollovers: '.$rollovers.'<br> PHP News system: '.$news.'<br> Flash Nav: '.$flash.'<br>Total Price: $'.$cost.'<br>Payment Method: '.$payment.'<br> Design Info: <table width="425" height="234" border="0">'.$design;
$info2 = '<html><body>Name: '.$name.'<br>Username is : '.$username.'<br> Email is : '.$email.'<br>Package: '.$pack.'<br> Rollovers: '.$rollovers.'<br> PHP News system: '.$news.'<br> Flash Nav: '.$flash.'<br>Total Price: $'.$cost.'<br>Payment Method: '.$payment.'<br> Design Info: <table width="425" height="234" border="0">'.$design.'</table></body></html>';
echo $info;
echo '<td>Are you sure this order is correct?'.'<td><form>
<input type=button value="Yes" onClick="goToURL1()">       <input type=button value="No" onClick="goToURL2()">
</form></table>';
$_SESSION['info'] = $info2; 
$_SESSION['email'] = $email;
$_SESSION['pass'] = $pass2;
$_SESSION['name'] = $name;
$_SESSION['username'] = $username;
}elseif ($username == ""){echo '<font color="red">Please enter a Username</font>';
include 'form.php';}elseif ($package == ""){echo '<font color="red">Please Select a package.</font>';
include 'form.php';}} else { echo '<font color="red">Please enter a valid email address.</font>';
include 'form.php';}
	}
}
?></body>
</html>
I know its messy, but im still a n00b.

Posted: Mon Jul 19, 2004 12:10 am
by turbo2ltr
Hmm...store all the params in the session.. :?:

The way I do it is I have one php file that displays the form as well as processes it. I pass it an action and use switch..

Code: Select all

switch($action)
{
   case "submit":
   { // process posted info here
        if($goodinfo)
            // output good info screen
        else 
             ShowForm();
   }
   break;
   
   default:
   {
       ShowForm();
    }
    break;
}

function ShowForm()
{
    // output form
    echo "<input type=text value="$_POST['name']">"; // fills the form with the posted data
    echo "<input type=hidden name="action" value="submit">";  // passes the action to php
}
This is just one example...I'm sure there are a ton of other ways...

Posted: Mon Jul 19, 2004 12:12 am
by feyd
you can use sessions to save off the filled in data, then if one it set, set that as the value (or selection, depending on its function)..