Forum Moderators: coopster

Message Too Old, No Replies

Login Form Problems

         

yarni

9:41 pm on Sep 26, 2005 (gmt 0)

10+ Year Member



I have a login form that checks for correct entries (with php). My problem is this :
When a user has filled in all the form, ticked the radio buttons and selected from drop down boxes the input is checked.

If an error is made (i.e. userid already in use. The form remembers the text that has been input but not the radio buttons that were ticked nor the selected input from a drop down box?

Is there a way for it to save all the input fields even if the screen refreshes?

thanks

Yarni

henry0

11:26 pm on Sep 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome Yarni to WebMasterWorld!

You mentioned PHP
so this should possibly be posted in the PHP forum

to answer to your question:
you need a DB to be fed with the form input and then query and output the stored values

yarni

7:28 am on Sep 27, 2005 (gmt 0)

10+ Year Member



I didn't really want to post to the database until all the fields were entered correctly.

Can the form input be held temporarily anywhere else and if so how?

Thanks

Yarni

henry0

10:31 am on Sep 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, we are back to server side programming.

When using a form one should not let the input being posted until it match the programmer requirements.
For instance, check for bogus email addresses, check for unauthorized signs in user name and of course check for missing field or for example if an user name has already been chosen by a previous poster etc....

It can also I presume be done in JS but I am not a JS person!

tomda

11:01 am on Sep 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes Yarni,

FIRST - JAVASCRIPT
******************
You should check that everything is filled correctly using Javascript (empty fields, wrong characters, etc...).
To check if username has already been used, you could use AJAX method. Simple and efficient, though a bit slow.

If everything is true, than the user can finally submit the form

SECOND - PHP
************
Even if I used Javascript to check that everything is correct, I still verify all variables using PHP after the form has been submitted AND before running any query (INSERT, UPDATE, etc.). Just to be on the safe side, especially for user having Javascript disable.
e.g. yesterday, I managed to register entering fake email address by disabling my Javascript. The webmaster forgot to write a solution for non javascript users! And I am sure there are many other websites with similar error.

yarni

6:07 pm on Sep 27, 2005 (gmt 0)

10+ Year Member



sorry, not sure if that helps?

I have a form that asks for (sample of some of the inputs) :

username : <varchar 20>
password : <password>
contact address : <var char ....>
property type : <drop down box>
beach : <radio buttons - y or n>

Now when a user fills in the whole form the php scripts checks various things on the form.
If the user has missed a field or tapped in an incorrect field the form refreshes and the text based input still shows BUT

the user loses the input they have chosen in the drop down box (reverts back to "select") and the radio button fileds (y/n) are both empty.

How do I keep the drop down boxes and radio fields showing what the user has already input.

Cheers

Yarni

henry0

6:30 pm on Sep 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I presume that you are using a downloaded script

The “varchar” indicates that you are indeed using a DB
It shows that a specific length of the input is predefined and that it will be inputted in a particular field (up to 256)

When using a backbrowser move most form retains most of the data but never a PW.
if the user is sent back to the login then it will not retain any info.

Without looking at the code we cannot help.

yarni

7:19 pm on Sep 27, 2005 (gmt 0)

10+ Year Member



Would you mind if I sent you the script by e-mail?

henry0

8:30 pm on Sep 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We wish everyone to participate so we benefit from each other
Posts the form script
The form goes somewhere... find in the form something like
<form action="http://www.somethingcom/someScript.php” method="post">
and post that someScript.php.
or it goes to “self” and the code will be included with the rest of the form

Do change by whatever real url etc....

yarni

8:54 pm on Sep 27, 2005 (gmt 0)

10+ Year Member



Ok here goes - this is the form script.

Ive took out someof the requested fields as it was massive!

<?php

session_start();
include *************
switch (@$_GET['do'])
{
case "login":
$connection=mysql_connect($host,$user,$password)
or die ("Couldn't connect to server.");
$db=mysql_select_db($database,$connection)
or die ("Couldn't select a database.");

$sql="SELECT loginname FROM ********
WHERE loginname='$_POST[fusername]'";
$result=mysql_query($sql)
or die ("Couldn't execute query.");
$num=mysql_num_rows($result);
if ($num == 1) //login name was found
{
$sql="SELECT loginname FROM ***********
WHERE loginname='$_POST[fusername]'
AND password=password('$_POST[fpassword]')";
$result2 = mysql_query($sql)
or die("Couldn't execute query 2.");
$num2=mysql_num_rows($result2);
if ($num2 > 0) //password is correct
{
$_SESSION['auth']="yes";
$logname=$_POST['fusername'];
$_SESSION['logname'] = $logname;
$today=date("Y-m-d h:m:s");
$sql = "INSERT INTO **** (loginname,logintime)
VALUES ('$logname','$today')";
mysql_query($sql) or die("Can't execute query.");
header("Location: *******************");
}
else // password is not correct
{
unset($do);
$message="The login name, '$_POST[fusername]'
exists, but you have not entered the correct password!
Please try again.<br>";
include("form.php");
}
}
elseif ($num == 0) // login name not found
{
unset($do);
$message="The login name you entered does not exist!
Please try again.<br>";
include("form.php");
}
break;

case "new":
foreach($_POST as $field => $value)
{

if (ereg("(Name)",$field))
{
if (!ereg("^[A-Za-z' -]{1,50}$",$value))
{
unset($_GET['do']);
$message_new="$field is not a valid name.
Please try again.";
include("form.php");
exit();
}
}
$$field=strip_tags(trim($value));
} //end foreach

if (!ereg("^[A-Za-z' -]{1,50}$",$first_name))
{
unset($_GET['do']);
$message_new="$first_name is not a valid first name.
Please try again.";
include("form.php");
exit();
}

if (!ereg("^[A-Za-z' -]{1,50}$",$last_name))
{
unset($_GET['do']);
$message_new="$last_name is not a valid last name.
Please try again.";
include("form.php");
exit();
}

..........................................................

$connection=mysql_connect($host,$user,$password)
or die ("couldn't connect to server.");
$db=mysql_select_db($database,$connection)
or die ("Couldn't select database.");
$sql="SELECT loginname from *********
WHERE loginname='$newname'";
$result=mysql_query($sql)
or die("Couldn't execute query.");
$num=mysql_numrows($result);
if ($num > 0)
{
unset($_GET['do']);
$message_new="$newname already used. Select another member ID.";
include("form.php");
exit();
}
else
{
$today = date("y-m-d");
$rent="rent";
$sql="INSERT INTO ********* (advertise,loginname,createdate,password,first_name,last_name ............) VALUES
('$rent','$newname','$today',password('$newpass'),'$first_name','$last_name' ..............)";
mysql_query($sql);

$_SESSION['auth']="yes";
$_SESSION['logname'] = $newname;
/* send email to new member */

$homeemail="************************";

$query="SELECT * from ********** WHERE loginname='$newname'";
$result=mysql_query($query)
or die("Couldn't execute query.");
$row=mysql_fetch_array($result,MYSQL_ASSOC);
extract($row);

header("Location: new.php");
}
break;

default:
include("form.php");
}
?>

henry0

9:51 pm on Sep 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Radio buttons will not keep in browser memory the user choice
The only way around calls for heavy modif of your script
You need to allow the radio button value to be loaded in your db
Then along with the error message output their values
However this is not very useful

Another way around: split the script in two parts
A)Only PW and Username, which will make later easier the retrieving or resetting of PW
B)The rest of info
But if you did not participate in the making of your script you might face a tough task.