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";

        }       

    }

}

?>


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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.