form validation

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

VARUN006
New php-forum User
New php-forum User
Posts: 21
Joined: Tue Jul 12, 2011 3:51 am

form validation

Postby VARUN006 » Tue Jul 12, 2011 4:31 am

<html>
<head>
<title>
VALUES !@@!
</title>
<style type="text/css">
.error{color:red;}
</style>
</head>
<body>
<?php
$okay=true;
if(empty($_POST['name'])){
print'<p class="error">please enter ur name</p>';
$oaky=false;
}
if(empty($_POST['email'])){
print '<p class="error">please enter ur mail id</p>';
$okay=false;
}
if(empty($_POST['password'])){
print '<p class="error">please enter ur password</p>';
$okay=false;
}
if($_POST['password'] != $_POST['confirm password']){
print'<p class="error">your password does not match...</p>' ;
$okay=false;
}
if($okay){
print"done";
}

?>
</body>
</html>


this code is not working properly......when executed thiz code is giving unusual result....all the name of the variables taken here are exact and thr is no spelling mistake or any mistake in variables...pls help...

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: form validation

Postby egami » Tue Jul 12, 2011 4:38 am

1. There is a spelling mistake in your code.
check for the spelling of $oaky and not $okay

2. if (empty($_POST['variable'])) works, but that's assuming the variable exists.
Try this:

Code: Select all


if 
(isset($_POST['variable']) && !empty($_POST['variable'])) { 
  $okay 
= FALSE;
  echo '<p> OOps.. Variable isn\'t defined or is empty</p>';
  
$array[$_POST['variable']] = 0;
}
 else { 
  $array
[$_POST['variable']] = 1;
}


// for giggles..
echo '<pre>'; print_r($array); echo </pre>;
// 
 

VARUN006
New php-forum User
New php-forum User
Posts: 21
Joined: Tue Jul 12, 2011 3:51 am

Re: form validation

Postby VARUN006 » Tue Jul 12, 2011 4:46 am

i want a code which matches the password fields like as in
password:
confirm password:


if ($_POST ['password'] != $_POST ['confirm']){
print '<p class="error">your password does not match..</p>';
$okay=false;
}

is this code correct for password matching??

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: form validation

Postby egami » Tue Jul 12, 2011 4:57 am

I want a Ferrari California for less than 150k too, but I wont' get one.


Yes, assuming that your variables are defined as such.

<input type="password" name="password" value="">
<input type="password" name="confirm" value="">


then

if ($_POST['password'] !== $_POST['confirm']) {
echo "Passwords don't match. Please insert coin to continue.";
}

VARUN006
New php-forum User
New php-forum User
Posts: 21
Joined: Tue Jul 12, 2011 3:51 am

Re: form validation

Postby VARUN006 » Wed Jul 13, 2011 11:58 pm

i m fed up with my validation not working properly.....m giving both codes html form code as well as php form code...pls help...pls pls..

//html form code.....


<html>
<body>
<form action="realform001.php" method="POST">
name:<input type="text" name="name" size="10" /><br />
email:<input type="text" name="email" size="10" /><br />
password:<input type="password" name="password" size="10" /><br />
confirm password:<input type="password" name="confirm" size="10" /><br />
<input type="submit" value="submit">
</form>
</body>
</html>


//php form code...

<html>
<head>
<title>
Form
</title>
<style type="text/css">
.error{color:red;
font-family:verdana;
font-size:16px;}
</style>
</head>
<body>

<?php

$okay=true;

if (empty($_POST['name'])){
print "<p class='error'>please enter your name !!</p>";
$okay=false;
}

if (empty($_POST['email'])){
print "<p class='error'>please enter your desired email !!</p>";
$okay=false;
}

if (empty($_POST['password'])){
print"<p class='error'>please enter your password</p>";
$okay=false;
}
/*
if ($_POST['password'] !== $_POST['confirm']){
echo "wrong";
$okay=false;
}
*/

if($okay=true){
print('done');
}



?>

</body>
</html>

//pls help i need ur all help badly..

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: form validation

Postby egami » Thu Jul 14, 2011 4:45 am

step 1.
Drink something cold and refreshing.


step 2.
Slow down Kemosawbi..

step 3.
When the form is entered properly, it says.. Done.
Isn't that what you wanted?

step 4.
I told you that using empty() is a BAD idea, apparently listening to advice isn't your best quality.


step 5.
redo all of your empty statements to reflect the following:

if ($_POST['variable'] == '' || strlen($_POST['variable']) <= 2) {
echo "Oops, This cannot be blank or longer than 2 characters (variable is: $_POST[variable])<br>";
}

MMkay?

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: form validation

Postby egami » Thu Jul 14, 2011 4:52 am

Try this: (and donate $5.00 to a local charity or to your favorite Rotweiller Shelter)

Code: Select all


<html>
<head>
<title>
Form
</title>
<style type="text/css">
.error{color:red;
font-family:verdana;
font-size:16px;}
</style>
</head>
<body>

<?php



if ($_POST['name'] == '' || strlen($_POST['name']) <= 2) {
    
$error['NAME'] = "Name cannot be blank. Please enter a valid name.";
}

if (
$_POST['email'] == '' || strlen($_POST['email']) <= 2) {
    
$error['EMAIL'] = "Email is not valid. (Although I should use better email validation)";
}

if (
strlen($_POST['password']) <= 5) {
    
$error['PASSWORD'] = 'Password is too short. Please try again';
} elseif (
$_POST['password'] !== $_POST['confirm']) {
    
$error['PASSWORD'] = 'Passwords do not match. Please try again!';
}

if (!isset(
$error)) {
    echo 
"Hurray! We have a completed form!";
} else {
    foreach(
$error as $k => $v) {
        echo 
'<p>'.$v.'</p>';
    }
}


?>

</body>
</html>


VARUN006
New php-forum User
New php-forum User
Posts: 21
Joined: Tue Jul 12, 2011 3:51 am

Re: form validation

Postby VARUN006 » Thu Jul 14, 2011 9:18 pm

lol....thx a lot....finally it worked....:D :D...n yeah will surely donate......:)

VARUN006
New php-forum User
New php-forum User
Posts: 21
Joined: Tue Jul 12, 2011 3:51 am

Re: form validation

Postby VARUN006 » Fri Jul 22, 2011 10:28 am

what troubled me this time around is cookies......i understood its meaning n what does it do.....
but this line:
if(isset($msg)
is making me confused....as far as i knw the isset function is used to check wether the form is submitted or not...now then y is ($msg) is in parenthesis...wat does this line actually mean??will it check wether $msg value is submitted or not,or what will it do???i have not given any button or submit values $msg in the below code....kindly tell me what does this line actually does...


<?php
if(isset($_POST['submitted'])){
setcookie('font_size',$_POST['font_size']);
setcookie('font_color',$_POST['font_color']);
$msg = '<p>Your settings have been entered...click <a href="view.php">HERE</a>to
see them in action.</p>';
}
?>
<html>
<head>
<title>
CUSTOMIZE YOUR SETTINGS
</title>
</head>
<body>
<?php
if(isset($msg)){
print $msg;
}
?>

pls help.....

hoomanik
New php-forum User
New php-forum User
Posts: 5
Joined: Wed Feb 09, 2005 2:13 am
Location: USA
Contact:

Re: form validation

Postby hoomanik » Sat Jul 23, 2011 8:38 pm

"isset" only determines if a variable is set and it's not NULL. It has nothing to do with cookies . in your code it's just checking if the $msg variable has a value and if yes, it will be printed. and of course the $msg variable is set in this line :
$msg = '<p>Your settings have been entered...click <a href="view.php">HERE</a>to
see them in action.</p>';

VARUN006
New php-forum User
New php-forum User
Posts: 21
Joined: Tue Jul 12, 2011 3:51 am

Re: form validation

Postby VARUN006 » Sun Jul 24, 2011 9:26 pm

thx a lot brother.....:) :)

stevemcgee
New php-forum User
New php-forum User
Posts: 20
Joined: Mon Feb 27, 2012 3:38 am

Re: form validation

Postby stevemcgee » Sun Mar 11, 2012 8:20 pm

You are easy to check validation of your website. You are upload your website in w3validator. It gives the all error in your html. It is easy to way to solve your problem.

User avatar
JordanMRichards
New php-forum User
New php-forum User
Posts: 84
Joined: Mon Apr 23, 2012 7:43 am
Contact:

Re: form validation

Postby JordanMRichards » Thu Apr 26, 2012 11:30 am

nice

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14 Year Old Programmer & Graphic Artist, Confident and Courageous
Image

jorgea
New php-forum User
New php-forum User
Posts: 2
Joined: Sun Oct 09, 2011 9:39 pm
Contact:

Re: form validation

Postby jorgea » Sun Sep 08, 2013 11:20 am

Have you made the spelling correction in your code? That ought to repair the problem

































































Peter Pan was a highly popular cartoon character who children the world
over adored find cheap flights find cheap airline tickets cheap flight search cheap airfare deal cheap air travel cheap plane tickets cheap air flights cheap flights to florida cheap flights to las vegas cheap flights to europe cheap flights to spain cheap flights to london cheap flights to vegas cheap flights to hawaii cheap air plane tickets cheap air flights cheap flights to mexico cheap flights to mexico city discount travel tickets air travel discount airline tickets or tryr was set on fire lost the
prize mercury poisoning treatment lead poisoning antidote lead poisoning treatment mercury detox safe mercury detoxification aluminum chelation heavy metal detox for iron heavy metal detox in body metal detoxification heavy metal natural detox detox clay baths clay bath experiences detoxifying clay detoxifying bath bentonite detox bentonite clay detox bath magnetic clay bath clay baths for children the camp was set on fire e snow all melted detox diets for weight loss how to lose weight fast how to burn stomach fat what foods burn fat the fastest way to lose weight best way to lose weight foods that help you lose weight fast ways to lose weight foods that help lose weight what is the best way to lose weight foods to lose weight whats the fastest way to lose weight fastest inexpensive way to lose weight how to lose weight extremely fast how to lose weight super fast the lion roared all day


Return to “Your Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron