PHP Verification Script

J

JohnW-Mpls

Were can I find a PHP script to verify that two fields in a form match
each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get what
they applied for. To avoid this, I would like to add a second field
for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.
 
N

NN

Were can I find a PHP script to verify that two fields in a form match
each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get what
they applied for. To avoid this, I would like to add a second field
for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.


<?php

if ($_POST[ 'email1'] != $_POST[ 'email2']){

//error
echo "email 1 and email 2 do not match<br/>";
echo "please check them before resubmitting";

}else{

//process information - emails match

}


?>
 
J

Jonathan N. Little

NN said:
Were can I find a PHP script to verify that two fields in a form match
each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get what
they applied for. To avoid this, I would like to add a second field
for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.


<?php

if ($_POST[ 'email1'] != $_POST[ 'email2']){

I would trap for empty fields...

if ($_POST[ 'email1'] == '' || $_POST[ 'email1'] != $_POST[ 'email2']){

Another advisable feature is to trim whitespace from inputs before
testing, an errant leading or trailing "space" can be frustrating if a
user employs a cut'n paste shortcut...
 
R

Raymond Schmit

NN said:
Were can I find a PHP script to verify that two fields in a form match
each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get what
they applied for. To avoid this, I would like to add a second field
for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.


<?php

if ($_POST[ 'email1'] != $_POST[ 'email2']){

I would trap for empty fields...

if ($_POST[ 'email1'] == '' || $_POST[ 'email1'] != $_POST[ 'email2']){

Another advisable feature is to trim whitespace from inputs before
testing, an errant leading or trailing "space" can be frustrating if a
user employs a cut'n paste shortcut...

If he employs a cut'n paste method, he could write twice the wrong
adress :)
 
J

Jonathan N. Little

Raymond said:
On Thu, 30 Apr 2009 16:00:45 -0400, "Jonathan N. Little"
I would trap for empty fields...

if ($_POST[ 'email1'] == '' || $_POST[ 'email1'] != $_POST[ 'email2']){

Another advisable feature is to trim whitespace from inputs before
testing, an errant leading or trailing "space" can be frustrating if a
user employs a cut'n paste shortcut...

If he employs a cut'n paste method, he could write twice the wrong
adress :)

True, but it would be the *same* wrong address. Usually one who uses the
cut'n'paste method is cutting and pasting from an valid reference
source, else there is little advantage over typing it in....
 
N

Neredbojias

Were can I find a PHP script to verify that two fields in a form
match each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get
what they applied for. To avoid this, I would like to add a second
field for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.

If they're anything like me, they'll cut-and-paste from the first one,
anyway instead of retyping the whole shlemiel. It might be wiser to
"reflect" what is typed and ask for a yes-or-no confirmation.
 
J

JohnW-Mpls

Were can I find a PHP script to verify that two fields in a form match
each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get what
they applied for. To avoid this, I would like to add a second field
for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.


<?php

if ($_POST[ 'email1'] != $_POST[ 'email2']){

//error
echo "email 1 and email 2 do not match<br/>";
echo "please check them before resubmitting";

}else{

//process information - emails match

}


?>
Wonderful - just what I asked for.

Of course, I've yet to try it!! [g]

--
JohnW-Mpls
 
J

JohnW-Mpls

NN said:
Were can I find a PHP script to verify that two fields in a form match
each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get what
they applied for. To avoid this, I would like to add a second field
for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.


<?php

if ($_POST[ 'email1'] != $_POST[ 'email2']){

I would trap for empty fields...

if ($_POST[ 'email1'] == '' || $_POST[ 'email1'] != $_POST[ 'email2']){

Another advisable feature is to trim whitespace from inputs before
testing, an errant leading or trailing "space" can be frustrating if a
user employs a cut'n paste shortcut...

Good idea - Thanks!

--
JohnW-Mpls.
 
J

JohnW-Mpls

If they're anything like me, they'll cut-and-paste from the first one,
anyway instead of retyping the whole shlemiel. It might be wiser to
"reflect" what is typed and ask for a yes-or-no confirmation.

We have had enough problems with mistyped address entires to warrant
the chedcking. The subject site is for the physically impaired and
most are older people - many are not yet into cut&paste.

--
JohnW-Mpls
 
N

NN

Were can I find a PHP script to verify that two fields in a form match
each other?

I have a form that asks for the respondents email address and lately,
too many people type the address poorly and therefore, do not get what
they applied for. To avoid this, I would like to add a second field
for the address and then have a script to check for accurate
duplication.

I have done programming for years but have never gotten into PHP. I
have references for PHP but need some example to get me started.


<?php

if ($_POST[ 'email1'] != $_POST[ 'email2']){

//error
echo "email 1 and email 2 do not match<br/>";
echo "please check them before resubmitting";

}else{

//process information - emails match

}


?>
Wonderful - just what I asked for.

Of course, I've yet to try it!! [g]


there is a way to verify that the domain after the @ exists with a PHP
extension (i forget if it's part of PECL or PEAR). this is not a 100%
fool proof though, since the domain may exist, but still the email not
be valid (ie (e-mail address removed)).

for more information you might want to check these:
php.net
pear.php.net

also, before the if statement above i'd check that the information was
actually submitted thru you form ( also checking that email1 is not
empty):

<?php


if (isset($_POST['submit']) && trim($_POST['email1'])!=""){


//rest of the code above




}


NN
 
N

Neredbojias

We have had enough problems with mistyped address entires to warrant
the chedcking. The subject site is for the physically impaired and
most are older people - many are not yet into cut&paste.


Yeah, I know what you mean. I'm kinda an old geezer myself and the
other day I was trying to install a red light in the bedroom to "add to
the mood" and, hell, I couldn't even get it up...
 
N

Neredbojias

Sure you didn't mean "black light?" And day-glo flowers on the wall?
Far out, man!


Black Light wasn't too available 'round where I lived. When I finally
got one, I was a little old for the "thrill" of it, then I broke the
damn thing 3-4 days later to boot. Ergo, you could say I'm a
psychedelic failure.
 
N

Neredbojias

If ya gotta fail it is good to do it spectacularly. ;-)


Which brings-up the old adage "Is it better to succeed mundanely or
fail spectacularly?" Actually, somebody who does nothing right is a
success at failing so God has provided for us all in one way or
another...
 
N

Neredbojias

I understand the notion you've expressed. Still, simply failing?
Without any eclat? I think that failure provides as much
instruction, or more, as great success. Of course, as you indicate,
doing nothing right, ever, is hardly good. But, sometimes doing
poorly can be wonderfully instructive.

Sure. Another adage: "People learn by their mistakes." Of course, it
depends on the person, her state of mind, whether she *wants* to learn
or not and has the ability. I, myself, learned html basically "by
mistakes" as I think do most page creators.
On the other hand, being lucky and right may be preferable to all of
this instructive goodness. I mean, there may be something to being
lucky and profitable versus knowledgeable and poor, eh?

I think it's a bit like saying (analogously) "Would you rather be smart
or happy?" The qualities are not absolutes nor mutually-exclusive but
if they were, I know which one I'd pick.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,266
Messages
2,571,078
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top