Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

PHP... is(not)set ?!

Options
  • 25-07-2005 2:26pm
    #1
    Registered Users Posts: 8,488 ✭✭✭


    taking info from a html form (POST), I want to do the echo and include if the values are left blank. The following doesn't work...

    [php]if (empty($_POST) OR empty($_POST)){
    echo "<p align=center style=\"color: white;\">Please fill in all required fields</p>";
    include ("include/confirm.php");
    }[/php]
    ...anyone know what will? is there something like an 'isnotset' option?

    cheers.


Comments

  • Closed Accounts Posts: 4,655 ✭✭✭Ph3n0m


    use this

    <?
    if ((!isset($_POST['name'])) || (!isset($_POST['email']))){
        echo "<p align=center style=\"color: white;\">Please fill in all required fields</p>";
        include ("include/confirm.php");
    } 
    ?>
    


  • Registered Users Posts: 8,488 ✭✭✭Goodshape


    this didn't work actually.. went for an ugly workaround in the end.

    cheers anyway.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Goodshape wrote:
    this didn't work actually.. went for an ugly workaround in the end.

    cheers anyway.
    Be aware that for Form variables, even if the user leaves a field blank, it still gets submitted as the empty string. It's a PITA but you have to check for both
    !isset($_POST) and $_POST != ""

    :(

    (You could also use preg_match() for a more comprehensive solution to ensure that the user doesn't insert a field full of spaces, etc)


  • Registered Users Posts: 2,157 ✭✭✭Serbian


    seamus wrote:
    (You could also use preg_match() for a more comprehensive solution to ensure that the user doesn't insert a field full of spaces, etc)

    preg_match() is a bit overkill, just use trim(). I would imagine that preg_match is slower than trim too, but I'm sure in the grand scheme of things you wouldn't really notice.


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Serbian wrote:
    preg_match() is a bit overkill, just use trim(). I would imagine that preg_match is slower than trim too, but I'm sure in the grand scheme of things you wouldn't really notice.
    Ultimately you can (should?) use preg_match() or something equivalent to validate all input, e.g. to prevent text being entered for a numeric field, etc. I'm sure there's a remove_text() function already written for that or something. Using preg_match() is not something I've ever done though. :)


  • Advertisement
Advertisement