Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

form validation

Codes here !

Moderators: macek, egami, gesf

form validation

Postby anand » Mon Dec 30, 2002 6:49 am

I have the following code

<html>
<head><basefont face="Arial"></head>
<body>

<?php
include "mailvalid.php";

if(email_valid($email==o)) //failure
{
echo"$email is not valid";
?>
<h2>User Profile</h2>
<form action="<?=$PHP_SELF?>" method="POST">

<b>Name</b><br>
<input type="text" name="name" size="15"><br>


<b>Email address</b><br>
<input type="text" name="email" size="20"><p>



<input type="submit" name="submit" value="submit">
</form>
<?php
}
else
{
echo "$email is valid adding to database";
?>
<form method="post" action="addtotable.php">

<b>Name</b><br>
<input type="text" name="name" size="15"><br>


<b>Email address</b><br>
<input type="text" name="email" size="20"><p>



<input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
</body> </html>




Can somebody tell me how to n=make this work I have email valid function in mailvalidator once somebody eneter the mail address on form this cheks and returns is it ok or not,if it is ok I want to add this info to database otherwise I want to give warning and show the same page <php_self>

Any ideas?

Regards
anand
anand
New php-forum User
New php-forum User
 
Posts: 2
Joined: Wed Dec 04, 2002 8:07 am

Postby Joan Garnet » Mon Dec 30, 2002 2:09 pm

You should use javascript to do that.
It's a waste of validating a form with server side language, and it overcharges the net.
Actually javascript was made exactly for this reason.

There's a function that works quite good -->
indexOf
It checks for a string in a string.

Code: Select all
var my_string = "jgarnet@ebcn-records.com";
var check_a = my_string.indexOf('@');
var check_dot = my_string.indexOf('.');
if ( (check_a == -1) || (check_dot == -1) )
 {
  alert('Your email is not valid');
 }
else
 alert('Thanks!');
}


bye!
User avatar
Joan Garnet
Moderator
Moderator
 
Posts: 387
Joined: Sat Aug 03, 2002 2:56 am
Location: Mars


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.