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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validation run before submitting submit button

    <?php
    {
    include ('connection.php');

    if(isset($_POST['Submit']))
    {
    $optid = $_POST['operator_id'];
    $optdec = $_POST['operater_description'];
    $empid = $_POST['employee_id'];
    $empmail = $_POST['employee_emailid'];
    $pwd = $_POST['user_password'];
    $langcd = $_POST['language_code'];
    $multl = $_POST['multi_language'];
    $lpwd = $_POST['last_password'];
    $accl = $_POST['account_lock'];
    $optt = $_POST['operator_type'];
    $optrals= $_POST['operatorid_alias'];
    $lsing = $_POST['last_signin'];
    $lupdt = $_POST['last_update'];
    $lupid = $_POST['lastupdate_operatorid'];

    }

    if (!isset($optid) || empty($optid))
    {
    echo '<script type="text/javascript">alert("Please enter operator id!");</script>';
    }
    if (!isset($optdec) || empty($optdec))
    {

    echo '<script type="text/javascript">alert("Please enter operater description!");</script>';
    }
    if (!isset($empid) || empty($empid))
    {

    echo '<script type="text/javascript">alert("Please enter employee id!");</script>';
    }
    if (!isset($empmail) || empty($empmail))
    {

    echo '<script type="text/javascript">alert("Please enter employee emailid!");</script>';
    }
    if (!isset($pwd) || empty($pwd))
    {

    echo '<script type="text/javascript">alert("Please enter user password!");</script>';
    }
    if (!isset($langcd) || empty($langcd))
    {

    echo '<script type="text/javascript">alert("Please enter language code!");</script>';
    }
    if (!isset($multl) || empty($multl))
    {

    echo '<script type="text/javascript">alert("Please enter multi language!");</script>';
    }
    if (!isset($lpwd) || empty($lpwd))
    {

    echo '<script type="text/javascript">alert("Please enter last password!");</script>';
    }

    >

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,899
    Thanks
    15
    Thanked 226 Times in 226 Posts
    To validate before submitting the form, you pretty much have to use javascript, if the form is valid you can have JS submit it too. There's tons of JS validation scripts out there, pretty much take your pick, or write your own. The !isset code doesn't really mean anything, the form field can be blank but still set. It only has to be an input with a name to be set.

    Also you can simplify your code by looping over $_POST.

    You can validate after submission and return to the form page with the fields refilled and any notices echoed, but that takes different code.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Nope.
    You need to use JS for client side validation. Of course, you'll still need to validate server side since client side validation is unreliable. Look into ajax if you'd like to mix the JS and the PHP together, but note that you will consume substantially more bandwidth in doing so (and you'll still need to validate on the server side).
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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