简体   繁体   中英

php 2 page form validation with css

I am trying to use php for my form validation for the first time. I get how to build my errors array and display it. Can anyone explain a technique that I could use to color the field with the error in the form? Dont even know where to start to attempt this. My forms are processed on a separate page.

You could use a multidimensional array:

$pass = $_POST['pass'];
$error[0] = array("Your password must be 8-20 characters in length", "red")
if(str_len($pass) > 20 || str_len($pass) < 8){
    $finalError = $error[0];
}

And the HTML:

<input style="background-color:<?echo $finalError[1]?>" name="pass"/>

This is assuming you aren't using ajax to validate...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM