AE117 Posted April 24, 2009 Share Posted April 24, 2009 Heres what I want to do I want to see if the field is blank Which I have just fine. What I want it to do is check the field and then change the color of that field if it is blank. Heres what I have <link href="style.css" rel="stylesheet" type="text/css"> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="login_form" id="login_form"> <p> <label>UserName <input type="text" name="user_name" id="user_name"> </label> </p> <p> <label>Enter Your Password <input type="password" name="user_password" id="user_password"> </label> </p> <p> <input type="submit" name="submit" id="submit" value="Enter"> </p> </form> <p> <?php require_once ('connect.php'); if(!$dbconnect = mysql_connect($host, $user, $pass)) { echo "Connection failed to the host 'localhost'."; exit; } if (!mysql_select_db($database)) { echo "Cannot connect to database"; exit; } foreach($_POST as $value) { if ($value == "") { echo "Please enter you Information"; echo "<input name='user_name' class='error' id='user_name'>"; } } ?> the class that i have for the css style is .error thanks Quote Link to comment https://forums.phpfreaks.com/topic/155549-solved-if-field-is-blank-change-color/ Share on other sites More sharing options...
NaveAdair Posted April 24, 2009 Share Posted April 24, 2009 Disregard this... >_> Quote Link to comment https://forums.phpfreaks.com/topic/155549-solved-if-field-is-blank-change-color/#findComment-818584 Share on other sites More sharing options...
mikesta707 Posted April 24, 2009 Share Posted April 24, 2009 Im assuming you want to do this if like, the user tries to log in or register, leaves a field blank, and you take them back to the page and say, hey color the field the left blank. While you can do this with php, it would be a lot easier, and a lot smoother to do this with javascript in my opinion. If you dont know how, read a tutorial on how javascript interacts with the HTML DOM. Its actually very easy to do with javascript, and honestly would only use a couple of functions consisting of 10-15 lines of code each Quote Link to comment https://forums.phpfreaks.com/topic/155549-solved-if-field-is-blank-change-color/#findComment-818591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.