How do i make this form sticky?

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 2172 Views - Last Post: 31 January 2009 - 04:06 AM Rate Topic: -----

#1 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

How do i make this form sticky?

Posted 26 January 2009 - 05:13 AM

i m posting code which i m using , please can you tell me how do can i make it sticky??


<?php
	session_start();
?>


<!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>Registration Form</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript"> 
var l;
var x= document.getElementById('code');
var y= document.getElementById('roll');
function validate(form) { 
	
	l=document.Reg.fname.value;
	if (l.length < 1) { alert("Please Enter first name"); 	document.Reg.fname.focus();
		 return false;
	
		 } 

		l=document.Reg.lname.value;
	if (l < 1) { alert("Please Enter last name!!!!"); 
	 	document.Reg.lname.focus();
return false; } 
	
l=document.Reg.roll.value;
if(l.length < 5 || l.length > 5) { alert("please fill in the roll number properly");
	document.Reg.roll.focus();
return false; }

	var numericExpression = /^[0-9]+$/;
if(document.Reg.roll.value.match(numericExpression))
	{
		return true;
	}
else 
	{	alert("YOU HAVE TO ENTER NUMBERS ONLY IN ROLL NUMBER");
		document.Reg.roll.focus();
		return false;
	}


l=document.Reg.login.value;
if (l.length < 6) { alert("Please Enter proper USERNAME"); 
	document.Reg.login.focus();
 return false; } 


	l=document.Reg.password.value;
if (l.length < 6) { alert("Please Enter proper PASSWORD!!!!"); 
		document.Reg.password.focus();
return false; }

	l=document.Reg.cpassword.value;
if (l.length < 6) { alert("Please Enter proper confirm PASSWORD!!!!"); 
	document.Reg.cpassword.focus();
 return false; } 



	l=document.Reg.hq.value;
if (l.length < 1) { alert("Please Enter Hint Question!!!!"); 
	document.Reg.hq.focus();
 return false; } 
	
	l=document.Reg.ans.value;
if (l.length < 1) { alert("Please Enter Answer!!!!"); 
	document.Reg.ans.focus();
 return false; } 

return true;
}


</script>
</head>
<?php
		if( isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) >0 ) {
			echo '<ul class="err">';
			foreach($_SESSION['ERRMSG_ARR'] as $msg) {
				echo '<li>',$msg,'</li>'; 
			}
			echo '</ul>';
			unset($_SESSION['ERRMSG_ARR']);
		}
	?>
<body>
<noscript>
<center><h3> Please Enable Javascript for Better Performance Of Website </h3></noscript>
<form id="Reg" name="Reg" method="post" action="" onsubmit="return validate(this)" >

  <table width="600" border="0" align="center" cellpadding="2" cellspacing="0">
	<tr>
	  <th>First Name </th>
	  <td>
<input name="fname" type="text" class="textfield" id="fname" title="enter your first name here" ></td>
	</tr>
	<tr>
	  <th>Last Name </th>
	  <td><input name="lname" type="text" class="textfield" id="lname" title="enter your last name here"/></td>
	</tr>
	<tr>
	  <th> Enter your roll number (5 digit)</th>
	  <td><input name="roll" tye="input" class="textfield" id="roll" title="enter your ROLL NUMBER here DIGIT ONLY"/></td>
	  </tr>
	<tr>
	  <th width="124">Login 6 characters minimum</th>
	  <td width="168"><input name="login" type="text" class="textfield" id="login" title="Login ID OF 6 Chars minimum"/></td>
	</tr>
	<tr>
	  <th>Password 6 characters minimum</th>
	  <td><input name="password" type="password" class="textfield" id="password" title="enter your Password"/></td>
	</tr>
	<tr>
	  <th>Confirm Password </th>
	  <td><input name="cpassword" type="password" class="textfield" id="cpassword" title="enter your Confirmed Password"/></td>
	</tr>
	<tr>
	  <th> Enter your code </th>
	  <td><input name="code" type="text" class="textfield" id="code" title="enter your Code "/></td>
	  </tr>
	  <tr>
	  <th> Enter Hint Question</th>
	  <td><input name="hq" class="textfield" id="hq" title="Hint Question Required for password recovery" /></td>
	  </tr>
	  <tr>
	  <th>Enter Answer of Hint Question </th>
	  <td><input name="ans" type="text" class="textfield" id="ans" title="Remember answer needed for password recovery"	 /></td>
	  </tr>
	<tr>
	  <td>&nbsp;</td>
	  <td><input type="submit" name="Submit" value="Register" /></td>
	</tr>
  </table>
</form> 
</body>
</html>
<?php
//	if($_GET['action'] == 'check')
//{

	//Start session
	session_start();
	
	//Include database connection details
	require_once('config.php');
	
	//Array to store validation errors
	$errmsg_arr = array();
	
	//Validation error flag
	$errflag = false;
	$movflag;


	//Connect to mysql server
	$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

	if(!$link) {
		die('Failed to connect to server: ' . mysql_error());
	}
	
	//Select database
	$db = mysql_select_db(DB_DATABASE);
	if(!$db) {
		die("Unable to select database");
	}

	
	//Function to sanitize values received from the form. Prevents SQL injection
	function clean($str) {
		$str = @trim($str);
		if(get_magic_quotes_gpc()) {
			$str = stripslashes($str);
		}
		return mysql_real_escape_string($str);
	}
	
	//Sanitize the POST values
	$fname = clean($_POST['fname']);
	$lname = clean($_POST['lname']);
	$login = clean($_POST['login']);
	$password = clean($_POST['password']);
	$cpassword = clean($_POST['cpassword']);
	$code=clean($_POST['code']);
	$roll=clean($_POST['roll']);
	$hq=clean($_POST['hq']);
	$ans=clean($_POST['ans']);

	//Input Validations
	if($fname == '') {
		$errmsg_arr[] = 'First name missing';
		$errflag = true;
	}
	if($fname != '')
	{
	if(!ctype_alpha($fname))
	{
		$errmsg_arr[]='ENTER ONLY "CHARACTERS" for FIRST NAME';
		$errflag=true;
	}
	}
	if($lname == '') {
		$errmsg_arr[] = 'Last name missing';
		$errflag = true;
	}
	if($lname != '')
	{
	if(!ctype_alpha($lname))
	{
		$errmsg_arr[]='ENTER ONLY "CHARACTERS " for LAST NAME';
		$errflag=true;
	}
	}

	if($roll=='')
	{
		$errmsg_arr[]='You must supply your 5 digit roll number';
		$errflag = true;
	}

	if(!$roll=='')
	{
		if(!ctype_digit($roll))
			{	
			$errmsg_arr[]='You have to Enter NUMBERS ONLY IN ROLL NUMBER';
			$errflag=true;
			}
		if(strlen((string)$roll) < 5)
		{
			$errmsg_arr[]='You have to Enter 5 DIGIT ROLL NUMBER';
			$errflag=true;
		}
	}

	
		 
/*	elseif(strlen($roll)<5)
	{
		$errmsg_arr[]='You must supply your 5 digit roll number';
		$errflag = true;
	}
	else {}
	
	*/

	$loglen=strlen($login);
	if($login == '') 
	{
		$errmsg_arr[] = 'Login ID missing';
		$errflag = true;
	}
	elseif ($loglen < 6)
	   {
		  $errmsg_arr[]='User ID must be of 6 characters minimum';
		  $errflag= true;   
	  }
	  else 
	  {
		  
	  }

	  $passlen=strlen($password);

	if($password == '') {
		$errmsg_arr[] = 'Password missing';
		$errflag = true;
	}
	 
	 elseif($passlen < 6)
	 {
	 	$errmsg_arr[]='Password must be of 6 characters minimum';
		  $errflag= true;
	 }
	 else
	 {
	 	
	 }
	if($cpassword == '') {
		$errmsg_arr[] = 'Confirm password missing';
		$errflag = true;
	}
	if( strcmp($password, $cpassword) != 0 ) {
		$errmsg_arr[] = 'Passwords do not match';
		$errflag = true;
	}
	/*if($code==''){
		$errmsg_arr[]='You must enter supplied code';
		$errflag = true;
	}*/
	if($code !='')
	{
		$qry= "select * from codes where code='$code'";
		$result=mysql_query($qry);
		if($result)
		{
			if(mysql_num_rows($result) > 0)
			{
				$movflag = true;
			}
			else 
			{
				$errmsg_arr[]="You have ENTERED WRONG CODE";
				$errflag=true;
			}
		}
	}
		else
		{
			$errmsg_arr[]='You must enter supplied code';
			$errflag = true;
		}
		if($hq=='')
		{
			$errmsg_arr[]='You must enter a Hint Question';
			$errflag = true;
		}
			if($ans=='')
		{
			$errmsg_arr[]='You must enter a Hint Question\'s Answer';
			$errflag = true;
		}
		
	
	//Check for duplicate login ID
	if($login != '') {
		$qry = "SELECT * FROM member WHERE login='$login'";
		$result = mysql_query($qry);
		if($result) {
			if(mysql_num_rows($result) > 0) {
				$errmsg_arr[] = 'Login ID already in use';
				$errflag = true;
			}
			@mysql_free_result($result);
		}
		else {
			die("Query failed");
		}
	}
	
	
	//If there are input validations, redirect back to the registration form
	if($errflag or !$movflag) {
		$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
		session_write_close();
	//	header("location: register-form.php");
		exit();
	}


	//Create INSERT query
	$qry = "INSERT INTO member (firstname, lastname,hintq, ans, login, passwd) VALUES('$fname','$lname','$hq','$ans','$login','".md5($_POST['password'])."')";
//	$qry = "INSERT INTO members(firstname, lastname, login, passwd) //VALUES('$fname','$lname','$login','".md5($_POST['password'])."')";
	$result = @mysql_query($qry);
	
	//Check whether the query was successful or not
	if($result) {
		$qry= "delete from codes where code='$code'";
		$test=mysql_query($qry);
			if($test)
			{
		header("location: register-success.php");
			}
			else 
			echo "Failed registration!!! You may try later";
		exit();
	}else {
		die("Query failed");
	}
//}
?>





sorry for so long code ... can't help ;)
i hope you can guide me!! :D

Is This A Good Question/Topic? 0
  • +

Replies To: How do i make this form sticky?

#2 Auzzie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: How do i make this form sticky?

Posted 26 January 2009 - 05:23 AM

By sticky do you mean like the way you can "pin" posts on forum's so they stay above the rest of the posts?
Was This Post Helpful? 0
  • +
  • -

#3 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 06:50 AM

sticky means details should be retained. after validation if some of the fields are blank then other fields which are filled should retain their values.
Was This Post Helpful? 0
  • +
  • -

#4 angrydwarfz  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 60
  • Joined: 07-December 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 07:30 AM

Do you mean something like this?

<input name="fname" type="text" class="textfield" id="fname" title="enter your first name here" value="
<? if(isset($_POST[fname])) echo $_POST[fname]; ?>" />



edit: typo

This post has been edited by angrydwarfz: 26 January 2009 - 08:42 AM

Was This Post Helpful? 0
  • +
  • -

#5 joeyadms  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 178
  • Joined: 04-May 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 08:39 AM

If you are not using a parsing engine, you will want all of your logic outside of the html, with just the values being echoed inside the html, it makes things clean, try something like this.

<?php

$frmVal = array(); // Set our value array
$field_names = array('fname','lname','address'); // Fields to populate
foreach($field_names as $field){
	// If our value exists in the POST superglobal, then save it, if not, create a blank value.
   if(isset($_POST[$field) && !empty($_POST[$field])){
		$frmVal[$field] = htmlentities($_POST['field']); // Decode if  html is supported
	} else {
		$frmVal[$field] = '';
	}
?>
<form method='POST'>
First name: <input type='text' name='fname' value="<?php echo $frmVal['fname']; ?>"/>
<!-- ..etc... -->
</form>



If you find it hard to maintain the array of field names, and want extensibility over performance, then instead of looking for specific keys in the $_POST array, just parse the entire array into our new $frmVal array.
Was This Post Helpful? 0
  • +
  • -

#6 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 08:52 AM

angry n joe (sorry using shortcut names :D) ty for your help i ll try to implement right now and tell you :)
Was This Post Helpful? 0
  • +
  • -

#7 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 09:32 AM

<? if(isset($_POST[fname])) echo $_POST[fname]; ?>"
its not working :((
Was This Post Helpful? 0
  • +
  • -

#8 Auzzie  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 43
  • View blog
  • Posts: 573
  • Joined: 20-January 09

Re: How do i make this form sticky?

Posted 26 January 2009 - 09:57 AM

slight typo there, try this
<? if(isset($_POST['fname'])) echo $_POST['fname']; ?>


you just needed to put quote marks around fname
Was This Post Helpful? 0
  • +
  • -

#9 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 11:07 AM

still not working even tried
<? php if(isset($_POST['fname'])) echo $_POST['fname']; ?>
Was This Post Helpful? 0
  • +
  • -

#10 angrydwarfz  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 60
  • Joined: 07-December 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 11:45 AM

View Postmandy011, on 26 Jan, 2009 - 10:07 AM, said:

still not working even tried
<? php if(isset($_POST['fname'])) echo $_POST['fname']; ?>


Try
<?php if(isset($_POST['fname'])) echo $_POST['fname']; ?>

Note the absent space between <? and php.
Was This Post Helpful? 0
  • +
  • -

#11 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 11:51 AM

@ angrydwarfz
dude i tried it still it doesnt work :|
Was This Post Helpful? 0
  • +
  • -

#12 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2934
  • View blog
  • Posts: 10,139
  • Joined: 08-August 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 12:00 PM

View Postmandy011, on 26 Jan, 2009 - 05:50 AM, said:

sticky means details should be retained. after validation if some of the fields are blank then other fields which are filled should retain their values.

I think you want to read up on the use of session variables.
Was This Post Helpful? 0
  • +
  • -

#13 angrydwarfz  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 60
  • Joined: 07-December 08

Re: How do i make this form sticky?

Posted 26 January 2009 - 12:25 PM

From what I see in the code, your script has no way to check whether the page was loaded for the first time (no need for the data sanitizing, sql query), or the form has already been submitted. ( the line checking that is commented out )

So what you should do is create an invisible field in the form name submitted, and set its value to true:
<input type="hidden" name="submitted" value="TRUE" />

Then when the script is executed, check if the form has already been sent:
 if(isset($_POST['submitted']))
{
if the data is valid
	{ insert data into db }
else
	{ alert the user that there are errors, print the form using the persistent data in the fields that are ok }
}
else // form hasn't been submitted yet
print the form




Hope it helps. :)

This post has been edited by angrydwarfz: 26 January 2009 - 12:28 PM

Was This Post Helpful? 0
  • +
  • -

#14 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

Re: How do i make this form sticky?

Posted 27 January 2009 - 06:46 AM

dude thanks for your reply :) i 'll check it out :)
Was This Post Helpful? 0
  • +
  • -

#15 mandy011  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 70
  • Joined: 27-September 08

Re: How do i make this form sticky?

Posted 31 January 2009 - 02:30 AM

i changed my mind and used sessions to store stuff ;D
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2