Jump to content

Form validator still submiting entries with errors


Mhang

Recommended Posts

Ubuntu

PHP

Mysql

 

So I got this form validator script online and I applied the validator part of it to my own form. My form requires a NAME and a SERIAL to be inputted and the SERIAL must be all numbers. I tested the validator by leaving NAME blank in my form and SERIAL all letters. The dispalyed resutls show the correct error messages: "Name : Please fill in a name for this computer." and "Serial : Please fill in a serial number for this computer." But the entry is still submitted with the errors and all.

 

Here is my validator script. It begins by calling the script I got online which is from this website: http://www.html-form-guide.com/php-form/php-form-validation.html


<?PHP

require_once "formvalidator.php";

 

    $validator = new FormValidator();

    $validator->addValidation("Name","req","Please fill in a name for this computer."):

    $validator->addValidation("Serial","req","Please fill in a serial number for this computer");

    $validator->addValidation("Serial","num","Serial number must be only numeric values");

    if($validator->ValidateForm())

    {

        echo "<h2>Validation Success!</h2>";

    }

    else

    {

        echo "<B>Validation Errors:</B>";

 

        $error_hash = $validator->GetErrors();

        foreach($error_hash as $inpname => $inp_err)

        {

            echo "<p>$inpname : $inp_err</p>\n";

        }       

    }

}

?>


Link to comment
Share on other sites

But the entry is still submitted with the errors and all.

 

Since you didn't show the compete code showing where you are using the submitted information, it will be a little hard for anyone to tell you what you did wrong.

 

If you put your code in the if(){} logic where the echo "<h2>Validation Success!</h2>"; is at, it should have worked correctly.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.