Jump to content

Sticky Form (Session variables)


14862875

Recommended Posts

Hey guys...could you please help me out with this simple form i have to develop..the user must enter his first and last names, e‐mail address and

a contact number into a form. The user must complete all the fields in the form. If he fails to

do so, a warning message should appear and the form should be displayed again already

containing the values of the fields he did complete – thus a ‘sticky’ form. When the user has

completed all the fields he should also be able to edit the information he entered. You can

enable this by storing his information as session variables, (i have know idea how to do this tho)..your help would be much appreciated...i have developed the index.php page as well as the form.php page...i'm getting a parse error on line 25, something to do with the '{' placement..

 

here is my code:

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Practical 8</title>

</head>
<body bgcolor="black">
<center>
<br/><br/>
<table border="0">
<tr>
<td background='b1.jpg' width='710' height='490' valign='top' style="text-align:left;color:white;font-family:tahoma;font-size:12;border:1 solid white;padding:20px;">


<span style="font-size:35">Practical 8</span><br/><br/>Please provide your information:<br/>All fields are compulsary!!


<?php

if(isset($_POST['submitted']))
{
if(empty($_POST['fname'])
{
print "<span style='color:red;font-weight:bold;'>Please fill out all fields</span><p/>";
include('form.php');
}
elseif (empty($_POST['lname'])
{
print "<span style='color:red;font-weight:bold;'>Please fill out all fields</span><p/>";
include('form.php');
}
elseif (empty($_POST['email'])
{
print "<span style='color:red;font-weight:bold;'>Please fill out all fields</span><p/>";
include('form.php');
}
elseif (empty($_POST['ctn'])
{
print "<span style='color:red;font-weight:bold;'>Please fill out all fields</span><p/>";
include('form.php');
}

else
{
include('form.php');	
}	

?>


</table>
</form>
</body>
</html> 

 

my form.php page code:

<form name="basic" action="index.php" method="post">

<table cellpadding="8" style="text-align:left;color:white;font-family:tahoma;font-size:12;padding:20px;">

<tr><td>First name:</td><td><input type='text' name='fname' value='<?php if(isset($_POST['fname'])) print $_POST['fname'];?>'</input></td></tr>
<tr><td>Last name:</td><td><input type='text' name='lname' value='<?php if(isset($_POST['lname'])) print $_POST['lname'];?>'</input></td></tr>
<tr><td>Email:</td><td><input type='text' name='email' value='<?php if(isset($_POST['email'])) print $_POST['email'];?>'</input></td></tr>
<tr><td>Contact number:</td><td><input type='text' name='ctn' value='<?php if(isset($_POST['ctn'])) print $_POST['ctn'];?>'</input></td></tr>

<input type="hidden" name="submitted" value="TRUE"/>

<tr><td><input type="submit" value="Submit"></td></tr>

</form>

Link to comment
https://forums.phpfreaks.com/topic/155701-sticky-form-session-variables/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.