PHP Verification Script

Discussion in 'HTML' started by JohnW-Mpls, Apr 30, 2009.

  1. JohnW-Mpls

    JohnW-Mpls Guest

    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

    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.
    JohnW-Mpls, Apr 30, 2009
    1. Advertisements

  2. JohnW-Mpls

    NN Guest


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

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


    //process information - emails match


    NN, Apr 30, 2009
    1. Advertisements

  3. 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...
    Jonathan N. Little, Apr 30, 2009
  4. If he employs a cut'n paste method, he could write twice the wrong
    adress :)
    Raymond Schmit, Apr 30, 2009
  5. 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....
    Jonathan N. Little, Apr 30, 2009
  6. JohnW-Mpls

    Neredbojias Guest

    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.
    Neredbojias, May 1, 2009
  7. JohnW-Mpls

    JohnW-Mpls Guest

    Wonderful - just what I asked for.

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

    JohnW-Mpls, May 1, 2009
  8. JohnW-Mpls

    JohnW-Mpls Guest

    Good idea - Thanks!

    JohnW-Mpls, May 1, 2009
  9. JohnW-Mpls

    JohnW-Mpls Guest

    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, May 1, 2009
  10. JohnW-Mpls

    NN Guest

    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 ).

    for more information you might want to check these:

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


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

    //rest of the code above


    NN, May 1, 2009
  11. JohnW-Mpls

    Neredbojias Guest

    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...
    Neredbojias, May 1, 2009
  12. JohnW-Mpls

    Neredbojias Guest

    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.
    Neredbojias, May 2, 2009
  13. JohnW-Mpls

    Neredbojias Guest

    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
    Neredbojias, May 3, 2009
  14. JohnW-Mpls

    Neredbojias Guest

    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.
    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.
    Neredbojias, May 4, 2009
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.