Hi anyone,
First of all congratulations on this wonderful forum!
I’m looking for a solution for a multipage php form . I’d to know how to pass vars from a page to the other. I’ve tried using hidden fields and sessions but don’t work. My problem is that pages are just ids inside in a single page.
I’d to make in any page that links to the next and in the last page a button to send the form (it’s easy but I cannot get vars from previous pages, so it gives errors for blank fields.
This is the code (I’ve dumb down it to understand better the problem):
PHP Code:
<?
$id=$_GET[id];
// ################### CONFIG ###################
$class_txt = "text";
$class_inputbutton = "inputButton";
$class_inputline = "inputLine";
$class_inputfield = "inputField";
$style_inputline = "width:355px;";
$style_inputfield = "width:355px;";
// email
$target_address = "info@email.it";
$email_subject = "Oggetto";
// error messages
$err_name = "name";
$err_email = "e-mail";
$err_tit = "title";
// misc text
$msg_date = "Date";
$msg_name = "Name";
$msg_email = "Email:";
$msg_tit = "Title ";
$txt_send = "Send";
$txt_mandatory = "required";
$msg_indent = 11;
// messages
$txt_thankyou = "<div class='$class_txt'><h2>Thank you!</h2></div>";
$txt_error = "<div style='color: #cc3300' class='$class_txt'><h2>Error! Check the follow fields:</h2>{errors}</div>"; // {errors} is replaced by the errors that occurred
// ################ END CONFIG #################
function spaces($num, $fill=" "){
$foo="";
for ($i=0; $i<$num; $i++) $foo.=$fill;
return $foo;
}
function isValidEmail($addr){
if(eregi("^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+\.[a-z]{2,4}$", $addr))
return true;
else
return false;
}
// start form evaluation
$error="foo";
if ($_REQUEST['do']=="send"){
$error=false;
if ($_REQUEST['name']=="") $error.="» $err_name<br>";
if ($_REQUEST['tit']=="") $error.="» $err_tit<br>";
if (!isValidEmail($_REQUEST['email'])) $error.="» $err_email<br>";
if ($error===false){
$message="$msg_date:".spaces($msg_indent-strlen($msg_date)).date("d M Y, H:i", time());
if ($_REQUEST['name']) $message.="\n$msg_name:".spaces($msg_indent-strlen($msg_name)).$_REQUEST['name'];
if ($_REQUEST['tit']) $message.="\n$msg_tit:".spaces($msg_indent-strlen($msg_tit)).$_REQUEST['tit'];
$message.="\n$msg_email:".spaces($msg_indent-strlen($msg_email))."mailto:".$_REQUEST['email'];
$message.="\n\n$msg_request:\n\n".$_REQUEST['message'];
mail($target_address, $email_subject, $message, "From: ".$_REQUEST['email']);
echo $txt_thankyou;
}else if ($error!==false) $error=str_replace("{errors}", $error, $txt_error);
}
if ($error!==false){
if($error!="foo") echo $error;
// form
echo "<script language='JavaScript' type='text/JavaScript'>\n";
echo "window.onload = function(){ document.form1.firma.focus(); }\n";
echo "</script>\n";
echo "<form name='form1' method='post' action=''>\n";
echo "<h2>FORM</h2>\n";
if ($id == '1') {
echo "<table border='0' class='txt'>\n";
echo "<tr><td class='$class_txt'>$msg_name *</td>\n";
echo "<td><input name='name' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['name']."'>\n";
echo "</td></tr>\n";
echo "</table>\n";
}
else if ($id == '2') {
echo "<table border='0' class='txt'>\n";
echo "<tr><td class='$class_txt'>$msg_tit *</td>\n";
echo "<td><input name='tit' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['tit']."'>\n";
echo "</td></tr>\n";
echo "</table>\n";
}
else {
echo "<table border='0' class='txt'>\n";
echo "<tr><td class='$class_txt'>$msg_email *</td>\n";
echo "<td><input name='email' type='text' class='$class_inputline' style='$style_inputline' value='".$_REQUEST['email']."'>\n";
echo "</td></tr>\n";
echo "<tr><td><input name='Submit' type='Submit' class='$class_inputbutton' value='$txt_send'>\n";
echo "<input name='do' type='hidden' id='do' value='send'></td>\n";
echo "</tr>\n";
echo "</table>\n";
}
echo "</form>\n";
}
?>
PS: Sorry for the language but im from Italian