Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2011
    Location
    California
    Posts
    54
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Submitting form after validation

    The thing i want to do
    If any field is empty -->User will see a message to fill out the field
    When both field is filled out and press Submit button --> goes to thankyou.php page


    <html>
    <head></head>
    <body>
    <?php
    $fname = $_POST['fname'];
    $lname = $_POST['lname'];
    ?>
    <form action="thankyou.php" method="POST">

    First Name: <input type="text" name='fname'/>
    <?php if(empty($fname)) echo "Please provide your First Name";?><br/>

    Last Name: <input type="text" name='lname'/>
    <?php if(empty($lname)) echo "Please provide your Last Name";?><br/>

    <input type="submit" value="submit" /><input type="reset" value="Clear Form"/>

    </form>
    </body>
    </html>


    thankyou.php
    <?php
    echo "Thank you $fname $lname for your time."
    ?>
    App Developer, Front End Designer and Learner at>> Facebook App Development Company - Cygnis Media

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Form validation of the pattern if(empty($fname)) is barely worthy of the name, and virtually useless, as even a single space, an X or a ? will return false, that is pass the validation.

    Form validation has been covered a zillion times in this forum - try using the search feature. Come back if you are still having problems.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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