Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

PHP... is(not)set ?!

  • 25-07-2005 02:26PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 8,488 ✭✭✭Goodshape


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

    cheers anyway.


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭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, Registered Users 2 Posts: 2,203 ✭✭✭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, Registered Users 2 Posts: 68,173 ✭✭✭✭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