i use both, just because i'm really anal about making sure users input data -- and if they have javascript turned on, it saves them headaches of clicking back and filling information again.
here is my user creation check, in the actual .html portion (javascript)
disclaimer: this could be written a lot better, but i threw it together in a couple minutes for someone
<pre>
<SCRIPT LANGUAGE="javascript">
<!-- hide
function passCheck(){
if (document.forms.join.username.value.length==0){
alert("You must enter an username.")
return false;}
if (document.forms.join.password.value.length==0){
alert("You must enter a password.")
return false;}
if (document.forms.join.password.value.length!=document.forms.join.password2.value.length){
alert("Your passwords do not match.")
return false;}
if (document.forms.join.email.value.length==0){
alert("You must enter an email.")
return false;}
if (document.forms.join.real_name.value.length==0){
alert("You must enter a real name.")
return false;}
if (document.forms.join.password.value.length<4){
alert("Your password must be at least four characters.")
return false;}
if (document.forms.join.password.value.length>8){
alert("Your password can not be more than 8 characters.")
return false;}
if (document.forms.join.b1.value.length==0){
alert("You must enter your birthdate.")
return false;}
if (document.forms.join.b1.value > 12){
alert("You must enter a month 1-12.")
return false;}
if (document.forms.join.b2.value > 31){
alert("You must enter a date 1-31")
return false;}
if (document.forms.join.b2.value.length==0){
alert("You must enter your birthdate.")
return false;}
if (document.forms.join.b3.value.length==0){
alert("You must enter your birthdate.")
return false;}
if (document.forms.join.secret_answer_1.value.length==0){
alert("You must enter an answer to the secret question.")
return false;}
if (document.forms.join.secret_answer_2.value.length==0){
alert("You must enter an answer to the secret question.")
return false;}
if (document.forms.join.address_line_1.value.length==0){
alert("You must enter at the minimum one shipping line.")
return false;}
if (document.forms.join.city.value.length==0){
alert("You must enter a city.")
return false;}
if (document.forms.join.state.value.length==0){
alert("You must enter a state.")
return false;}
if (document.forms.join.zipcode.value.length==0){
alert("You must enter a zipcode.")
return false;}
// if it makes it here, it will return true.
return true;
}
// unhide -->
</SCRIPT>
</pre>
okay.. and then in my join.php, here are a few of the checks i make:
<pre>
if ( ($username != "") && ($password != "") && ($email != "") ) {
$flag = 1; // this is a flag to make sure we don't have any errors from input
$feedback = "\n";
$real_name = stripslashes($HTTP_POST_VARS['real_name']);
// concatenate birthdate fields
$birthdate = '19';
$birthdate .= $HTTP_POST_VARS['b3'];
$birthdate .= '-';
$birthdate .= $HTTP_POST_VARS['b1'];
$birthdate .= '-';
$birthdate .= $HTTP_POST_VARS['b2'];
$username = stripslashes($HTTP_POST_VARS['username']);
$secret_answer_1 = stripslashes($HTTP_POST_VARS['secret_answer_1']);
$secret_answer_2 = stripslashes($HTTP_POST_VARS['secret_answer_2']);
// match username versus database to see if we get a match
$sql = "select username from {$DB_CONF['table_account']} where username='$username'";
$sql_result = mysql_query($sql) or die ("Couldn't execute query. (message_database()) ".mysql_error());
while ($row = mysql_fetch_array($sql_result)) {
$username_test = $row['username'];
}
if ( $username_test == $username ) { // okay someone already has that username..
$errormsg .= "Someone already has chosen $username.. please select another username.\n";
$flag = 0;
}
// no spaces in username
if (strrpos($username,' ') > 0) {
$errormsg .= "There cannot be any spaces in the login name.\n";
$flag = 0;
}
// illegal names
if (eregi("^((root)|(bin)|(daemon)|(adm)|(lp)|(sync)|(shutdown)|(halt)|(mail)|(news)"
. "|(uucp)|(operator)|(games)|(mysql)|(httpd)|(nobody)|(dummy)"
. "|(www)|(cvs)|(shell)|(ftp)|(irc)|(debian)|(ns)|(download))$",$username)) {
$errormsg .= "Illegal username.\n";
$flag = 0;
}
if (eregi("^(anoncvs_)",$username)) { // check for CVS in username
$errormsg .= "Name is reserved for CVS.\n";
$flag = 0;
}
// validate email
if( !ereg( "^([0-9,a-z,A-Z]+)([.,_]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_\,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2}([0-9,a-z,A-Z])?$", $email ) ) {
// email didn't pass check, redirect.
$errormsg .= "Your email address is <b>not valid</b> ..please enter a valid email address.\n";
$flag = 0;
}
if (!$flag) { // okay we have an error somewhere.. let's inform the user of it
echo "
<head>
<title>Error in Input</title>
</head>
<body>
<h1>There was an error in your input</h1>
error message:<p>
<pre>
<p align=left>$errormsg</p>
</pre>
<h3>Please click back on your browser and try to correct the errors.</h3>
</body>
";
}
else if ($flag) { // this means user has inputted correct values.. inserting into database
// code goes here to insert user into database, file, etc..
</pre>
hope this could help someone ;o)