Hi,
I am trying to use a multiple page form where text field and radio button inputs are remembered when back tracking, The website has recently been moved to a new server where it no longer works. The code is exactly the same.
Here is the code for the first form:
//<?php session_start(); ?>
<html>
<head>
<title>Sample Forms - Sticky</title>
</head>
<body>
<?php
$RN = '';
$GN = '';
$BS = '';
session_start();
$_SESSION['getroom'] = $_POST['roomnumber']; //description of project
$_SESSION['getgender'] = $_POST['gender']; //project type
$_SESSION['getbreksize'] = $_POST['breakfastSize']; //other information
if(isset($_POST['submit']))
{
//process the text-input field
if(isset($_POST['roomnumber']) && is_numeric($_POST['roomnumber']))
$RN = (int)$_POST['roomnumber'];
else
$RN = false;
//process the radio buttons
if(isset($_POST['gender']))
$GN = $_POST['gender'];
else
$GN = false;
//process the listbox
if(isset($_POST['breakfastSize']))
$BS = $_POST['breakfastSize'];
else
$BS = false;
//if all entries okay, process information, display message and exit script.
if($RN && $GN && $BS)
{
//...process information...
//echo '<p>Everything is in order...</p>';
//echo '</body></html>';
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=test2.php">';
//exit;
echo '</body></html>';
exit();
}
}
echo '<h2>Sample demonstration of Sticky Forms</h2>';
echo '<form name="Form1" action="' . $_SERVER['PHP_SELF'] . '" method="POST">';
//display text-input label for room-number
if(isset($_POST['submit']) && !$RN)
echo '<p><font color="red" size="+1"><b>! Room Number</b></font><br />';
else
echo '<p>Room Number<br />';
//display the text-input field
echo '<input type="text" name="roomnumber" maxlength="60" size="60"
value="' . $RN . '" /></p>';
//display the radio label for gender
if(isset($_POST['submit']) && !$GN)
echo '<p><font color="red" size="+1"><b>! Gender</b></font><br />';
else
echo '<p>Gender<br />';
//display the radio buttons
if($GN == 'M')
echo '<input type="radio" name="gender" value="M" checked />Male ';
else
echo '<input type="radio" name="gender" value="M" />Male ';
if($GN == 'F')
echo '<input type="radio" name="gender" value="F" checked />Female ';
else
echo '<input type="radio" name="gender" value="F" />Female ';
if($GN == 'N')
echo '<input type="radio" name="gender" value="N" checked />Not Sure</p>';
else
echo '<input type="radio" name="gender" value="N" />Not Sure</p>';
//-----
//display the label for the for listbox
if(isset($_POST['submit']) && !$BS)
echo '<p><font color="red" size="+1"><b>! Select the size of the Breakfast</b></font><br />';
else
echo '<p>Select the Size of the Breakfast<br />';
//build a 'selection' array
$select_array = range(1,3);
if($BS > 0)
$select_array[$BS] = 'selected';
//display the listbox
echo '<select name="breakfastSize" size="1">';
echo '<option value="" selected>Please Select</option>';
echo '<option value="3" '. $select_array[3] . '>King Size</option>';
echo '<option value="2" '. $select_array[2] . '>Normal Size</option>';
echo '<option value="1" '. $select_array[1] . '>Small Size</option>';
echo '</select></p>';
echo '<p><input type="submit" name="submit" value="submit"></p>';
echo '</form>';
echo '</body>';
echo '</html>';
here is the code for the second form :
//<?php session_start(); ?>
<html>
<head>
<title>Sample Forms - Sticky</title>
</head>
<body>
<?php
session_start();
$_SESSION['clientname'] = $_POST['name']; //name
$_SESSION['clientcompany'] = $_POST['company']; //company
$N = '';
$C = '';
if(isset($_POST['submit']))
{
//process the text-input field
if(isset($_POST['name']))
$N = $_POST['name'];
else
$N = false;
if(isset($_POST['submit']))
if(isset($_POST['submit']))
//process the text-input field
if(isset($_POST['company']))
$C = $_POST['company'];
else
$C = false;
//if all entries okay, process information, display message and exit script.
if($N && $C)
{
//...process information...
echo '<p>Everything is in order...</p>';
echo 'What is the roomnumber? : ';
echo $_SESSION['getroom'];
echo "<br>";
echo 'What is the gender? : ';
echo $_SESSION['getgender'];
echo "<br>";
echo 'Breakfast Size : ';
echo $_SESSION['getbreksize'];
echo "<br>";
echo 'Client Name : ';
echo $_SESSION['clientname'];
echo "<br>";
echo "Thank you for using our mail form";
//echo '<META HTTP-EQUIV="Refresh" Content="0; URL=success.html">';
//exit;
echo '</body></html>';
exit();
}
}
echo '<h2>Sticky Forms Last Page</h2>';
echo '<form name="Form1" action="' . $_SERVER['PHP_SELF'] . '" method="POST">';
//display text-input label for name
if(isset($_POST['submit']) && !$N)
echo '<p><font color="red" size="+1"><b>Please Specify</b></font><br />';
else
echo '<p>Please enter Name [required]<br />';
//display the text-input field
echo '<input type="text" name="name" maxlength="60" size="60"
value="' . $N . '" /></p>';
if(isset($_POST['submit']) && !$C)
echo '<p><font color="red" size="+1"><b>Please Specify</b></font><br />';
else
echo '<p>Please enter Company [required]<br />';
//display the text-input field
echo '<input type="text" name="company" maxlength="60" size="60"
value="' . $C . '" /></p>';
echo '<p><input type="submit" name="submit" value="submit"></p>';
echo '</form>';
echo '</body>';
echo '</html>';
If I use the forms in their current format, they work perfectly, the forms are sticky and the global variables are displayed as required, however I get the following errors on both pages :
Error on first page :
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/clients/client0/web17/web/forms_sticky2old.php:1) in /var/www/clients/client0/web17/web/forms_sticky2old.php on line 1
Error on second page :
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /var/www/clients/client0/web17/web/test2.php:1) in /var/www/clients/client0/web17/web/test2.php on line 1
If I remove session_start(); from within the forms (I have read this needs to be at the top of the script) and replace it with <?php session_start(); ?> the error messages no longer appear, the global variables come through but the the forms are no longer sticky.
Any help would be greatly appreciated, Thank you!