Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default PHP Form Validation...

    Hey,

    Does anyone know of any good methods of PHP form validation?

    Basically all I am after is a way for a user to submit a form, if they left out a required field alert them but keep all data they have already entered?

    +REP

    Lew.
    Im not here to be loved, I love to be hated :-}


  2. #2
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Basic.. but you should get the idea.

    PHP Code:
    <?php
    if($_POST) {
        
    $name $_POST["name"]; // clean this of course... 

        
    if($name == "") {
            
    $error "Name left blank..";
        } else {
            
    // wasn't blank..
        
    }

    }
    ?>

    <?php
    if($error != "") {
        echo 
    "<h1>ERROR!:</h1> <p>{$error}</p>";
    }
    ?>

    <form name="blah" method="post" action="index.php">
        <label>Name:</label>
        <input type="text" value="<?php echo $name?>" />
        <input type="submit" />
    </form>

  3. #3
    Join Date
    Jan 2010
    Location
    United Kingdom
    Posts
    846
    Tokens
    1,766
    Habbo
    triston220

    Latest Awards:

    Default

    PHP Code:
    <form action="index.php" method="post">
    <input type="text" name="Name">
    <input type="submit" name="submit" value="Gooo!">
    </form>

    <?php
    if (isset($_POST['submit'])) {  //Has the user pressed the button?
    if ($_POST['Name'] =='') {     //Is there a value for name?
    Echo "Enter a value";           //Not here.
    }else{
    echo 
    "validation passed!"//Yay, the user entered a value which was not null.
    }
    }
    ?>
    Last edited by triston220; 17-12-2010 at 03:46 PM.


    Quote Originally Posted by Jaaaack! View Post
    See, however much I want this, my girlfriend uses my PC too much, and I would be killed.





  4. #4
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by triston220 View Post
    PHP Code:
    <form action="index.php" method="post">
    <input type="text" name="Name">
    <input type="submit" name="submit" value="Gooo!">
    </form>

    <?php
    if (isset($_POST['submit'])) {  //Has the user pressed the button?
    if ($_POST['Name'] =='') {     //Is there a value for name?
    Echo "Enter a value";           //Not here.
    }else{
    echo 
    "validation passed!"//Yay, the user entered a value which was not null.
    }
    }
    ?>
    I found a solution in the end + the way you've done it, it wont keep the values in text boxes.

    Lew.
    Im not here to be loved, I love to be hated :-}


  5. #5
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Not trying to be a party pooper... but read the post next time before you try and offer a solution on what he wanted...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •