How do you test for blank form input?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts

  • Marcin Dobrucki
    Guest replied
    Re: How do you test for blank form input?

    BKDotCom wrote:[color=blue]
    > if ( !isset($_GET['whatever']) || ( empty($_GET['whatever']) &&
    > $_GET['whatever'] != 0) )[/color]

    php.net/empty

    "... As of PHP 4, The string value "0" is considered empty..."

    Leave a comment:


  • BKDotCom
    Guest replied
    Re: How do you test for blank form input?

    if ( !isset($_GET['whatever']) || ( empty($_GET['whatever']) &&
    $_GET['whatever'] != 0) )

    Leave a comment:


  • Smitro
    Guest replied
    Re: How do you test for blank form input?

    Chris Portka wrote:[color=blue]
    > This is a very simple question but after a long time I still can't find
    > an answer looking on my own. How do you test for no user input in a
    > form? Example:
    >
    > <form action="index.p hp" method="get">
    > Type your first name:
    > <input type="text" name="FirstName ">
    > <input type="submit" value="Submit">
    > </form>
    >
    > <?php
    > if ($_GET["FirstName"] == "")
    > {
    > echo "No user input";
    > }
    > ?>
    >
    > Is this the correct way to always test if there was nothing input by
    > the user in the form? Should I test for nil or something else?
    > Thanks,
    > Chris
    >[/color]
    I also use NULL some times...eg.
    if ($_GET["FirstName"] == NULL)

    Leave a comment:


  • Marcin Dobrucki
    Guest replied
    Re: How do you test for blank form input?

    Chris Portka wrote:
    [color=blue]
    > <?php
    > if ($_GET["FirstName"] == "")
    > {
    > echo "No user input";
    > }
    > ?>[/color]

    how about:

    if (isset($_GET['FirstName']) && empty($_GET['FirstName'])) {
    echo "yes, it's empty";
    }

    Specifically the "empty" function will be useful here, but sometimes its
    good to check that the variable actually exists.

    /Marcin

    Leave a comment:


  • Lisa Pearlson
    Guest replied
    Re: How do you test for blank form input?

    trim() and also look at empty()

    "Chris Portka" <chrisportka@gm ail.com> wrote in message
    news:1124330068 .912666.7920@g4 3g2000cwa.googl egroups.com...[color=blue]
    > This is a very simple question but after a long time I still can't find
    > an answer looking on my own. How do you test for no user input in a
    > form? Example:
    >
    > <form action="index.p hp" method="get">
    > Type your first name:
    > <input type="text" name="FirstName ">
    > <input type="submit" value="Submit">
    > </form>
    >
    > <?php
    > if ($_GET["FirstName"] == "")
    > {
    > echo "No user input";
    > }
    > ?>
    >
    > Is this the correct way to always test if there was nothing input by
    > the user in the form? Should I test for nil or something else?
    > Thanks,
    > Chris
    >[/color]


    Leave a comment:


  • black francis
    Guest replied
    Re: How do you test for blank form input?

    try

    if (trim($var) == "") //empty
    else //not empy

    Leave a comment:


  • Chris  Portka
    Guest started a topic How do you test for blank form input?

    How do you test for blank form input?

    This is a very simple question but after a long time I still can't find
    an answer looking on my own. How do you test for no user input in a
    form? Example:

    <form action="index.p hp" method="get">
    Type your first name:
    <input type="text" name="FirstName ">
    <input type="submit" value="Submit">
    </form>

    <?php
    if ($_GET["FirstName"] == "")
    {
    echo "No user input";
    }
    ?>

    Is this the correct way to always test if there was nothing input by
    the user in the form? Should I test for nil or something else?
    Thanks,
    Chris

Working...