|
|
Post a Project »
Find a Professional HTML Freelancer!
Find a Freelancer to help you with your HTML projects
| |
|
 |
|
|
07-06-2005, 04:58 AM
|
manditory fields
|
Posts: 216
Location: Boston, Ma
|
How would i go about having a form and making some of the fields manditory. You know how when you fill out like a forum sign up, if you didnt put in a username it would redirect you back to the form and put a red star by the fields you missed or incorrectly filled.
|
|
|
|
07-06-2005, 05:09 AM
|
|
Posts: 880
Location: Leeds UK
|
use javascript mate.
It saves that extra hit on the server just to say "hey fill in this field" where javascript can do all this client end and pop up a window saying "hey fill thi in".
Take a look in the javascript section there is plenty of examples in there.
ibbo
|
|
|
|
07-06-2005, 08:49 AM
|
|
Posts: 1,626
Location: Guildford, UK
|
If you have access to ASP.NET, you can use a variety of controls (RequiredFieldValidator, RegularExpressionValidator, CompareValidator, and custom validators) which will hndle both client and server side validation for you.
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"
Please login or register to view this content. Registration is FREE | Please login or register to view this content. Registration is FREE
|
|
|
|
07-06-2005, 05:44 PM
|
|
Posts: 216
Location: Boston, Ma
|
Right now i dont know ANY asp. I figure i maybe be able to do it with php but i'm not sure. Right now i do have some javascript onblur functions that check for errors in the numbers and e-mail addresses. What would i do like when they hit submit it checks to see if any fields are empty then gives a pop up message?
|
|
|
|
07-06-2005, 06:43 PM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
If you post the HTML for the form I will post you a simple JavaScript form checker that you can play around with.
|
|
|
|
07-06-2005, 07:46 PM
|
|
Posts: 237
|
PHP is another great way to deal with form validation if your visitors have Javascript disabled in their browsers, you don't know ASP or as in many cases have your site hosted on a Linux/Unix server that has limited support for ASP. PHP Freaks has many good tutorials on all aspects of PHP including forms. If you are less inclined to do it yourself I would also recommend doing a search on Google for PHP formmail scripts. There are many out there for free that you can use as is or modify to suit your needs.
Good Luck!
Kaiman
Storm King Design
Storm King Computer Consulting
|
|
|
|
07-07-2005, 03:24 AM
|
|
Posts: 86
Location: No Fixed Abode
|
Call the form below register.php
PHP Code:
<?PHP
##----[ PHP VARIABLES ]----##
/*set up the variable*/
$username = $_POST['username'];
$password = $_POST['password'];
$retype_password = $_POST['retype_password'];
$forenname = $_POST['forename'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$retype_email = $_POST['retype_email'];
/*remove white space from the input fields is there is any*/
$username = trim($username);
$password = trim($password);
$retype_password = trim($retype_password);
$forenname = trim($forname);
$surname = trim($surname);
$email = trim($email)
$retype_email = trim($retype_email);
##----[ FORM VALIDATION ]----##
/*check if any fields are empty*/
if((empty($username)) || (empty($password)) || (empty($retype_password)) || (empty($email)) || (empty($retype_email)) || (empty($first_name)) || (empty($surname))){
echo 'You did not submit the following required information! <br />';
if(empty($username)){
echo "Username is a required field. Please enter it below.<br />";
}
if(empty($password)){
echo "Password is a required field. Please enter it below.<br />";
}
if(empty($retype_password)){
echo "Retype Password is a required field. Please enter it below.<br />";
}
if(empty($email)){
echo "Email is a required field. Please enter it below.<br />";
}
if(empty($retype_email)){
echo "Retype Email is a required field. Please enter it below.<br />";
}
if(empty($first_name)){
echo "First Name is a required field. Please enter it below.<br />";
}
if(empty($surname)){
echo "Last Name is a required field. Please enter it below.<br />";
}
include 'http://www.yourDomain.com/register.php';
exit();
}
##----[ PASSWORD & EMAIL VALIDATION ]----##
/*check that the passwords and emails match then using the db see if the username is already in use*/
$sql_email_check = mysql_query("SELECT email FROM users WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM users WHERE username='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if(($password !== $retype_password) || ($email !== $retype_email) || ($email_check > 0) || ($username_check > 0)){
echo "Please fix the following errors: <br />";
if($password !== $retype_password){
echo "The passwords you have supplied do not match. Please re-enter your password!<br />";
}
if($email !== $retype_email){
echo "The Email addresses you have supplied do not match. Please re-enter your Email address!<br />";
}
if($email_check > 0){
echo "<strong>That Email address is already registered in our Database. Please submit a different Email address!<br />";
}
if($username_check > 0){
echo "The username you have selected is already in use. Please choose a different Username!<br />";
}
include 'http://www.yourDomain.com/register.php';
exit();
}
##----[ INSERT DATA INTO DB ]----##
/*encrypt the password*/
$db_password = md5($password);
/*insert data into db*/
$sql = mysql_query("INSERT INTO users (username, password, email, first_name, surname, gender, signup_date)
VALUES('$username', '$db_password', '$email', '$first_name', '$surname', '$gender', now())") or die (mysql_error());
/*error message*/
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
}
?>
<html>
<head>
<title>User Registration Form</title>
<style type="text/css">
.text
{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10;
font-weight:normal;
color:#000000;
}
.inputField
{
font-family:Verdana, Arial, Helvetica, sans-serif;
color:#000000;
font-size:10px;
font-wieght:normal;
border-color:#666666;
border-width:1px;
border-style:solid;
width:150px;
height:17px;
}
.button
{
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:10;
color:#000000;
height:17px;
width:50px;
border-color:#666666;
border-width:1px;
background-color:#CCCCCC;
}
</style>
</head>
<body>
<table class="text">
<tr>
<td><u>User Registration Form</u></td>
</tr>
</table>
<form name="signup_form" action="<?PHP echo $_SERVER['PHP_SELF'] ?>"> method="post">
<table class="text">
<tr>
<td align="right">Username:</td>
<td><input type="text" name="username" class="inputField"></td>
</tr>
<tr>
<td align="right">Forename:</td>
<td><input type="text" name="forname" class="inputField"></td>
</tr>
<tr>
<td align="right">Surname:</td>
<td><input type="text" name="surname" class="inputField"></td>
</tr>
<tr>
<td align="right">Passowrd:</td>
<td><input type="password" name="password" class="inputField"></td>
</tr>
<tr>
<td align="right">Retype Password:</td>
<td><input type="password" name="retype_password" class="inputField"></td>
</tr>
<tr>
<td align="right">Email:</td>
<td><input type="text" name="email" class="inputField"></td>
</tr>
<tr>
<td align="right">Retype Email:</td>
<td><input type="text" name="retype_email" class="inputField"></td>
</tr>
</table>
</form>
</body>
</html>
There is more that can be done to the code above but that has all the basics.
Last edited by Enigmatic; 07-08-2005 at 03:02 AM..
|
|
|
|
07-07-2005, 04:09 PM
|
|
Posts: 216
Location: Boston, Ma
|
i'll try playing around with thet script you posted, i should be able to figre out something 
|
|
|
|
07-07-2005, 08:49 PM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
Just a little point you might like to take into account - check the email address is a valid one. To do that use:
Quote:
|
if (!eregi ("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}$", $email)) { echo "The email address you entered does not conform to recognised standards. Please re-enter it.<br />"; }
|
|
|
|
|
07-08-2005, 04:45 AM
|
|
Posts: 216
Location: Boston, Ma
|
This may be a dumb question because its kinf of late here, but whats !eregi ?
|
|
|
|
07-08-2005, 05:48 AM
|
|
Posts: 159
Location: Skegness, Lincolnshire, England
|
!eregi is actually made up of two components the '!' and eregi. The '!' is the comparative operator for NOT - it's the shorthand way of saying, for example: if ($a != $b).
eregi() is a case insensitive regular expression match. It is the same as the php function ereg(), but ignores case distinction when matching alpabetic characters. For example (taken straight from the PHP manual):
PHP Code:
<?php
$string = 'XYZ';
if (eregi('z', $string)) {
echo "'$string' contains a 'z' or 'Z'!";
}
?>
If you want to have a ready reference to PHP on your desktop go to www.php.net/download-docs.php and select the chm.zip from top right of the list of languages the manual is available in. Its not a tutorial guide to PHP, so some of will more than likely make no sense at all, but it is a great reference, and as a CHM you have it in Windows help file format 
|
|
|
|
|
« Reply to manditory fields
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|