Jump to content

[SOLVED] If field is Blank change Color


AE117

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/155549-solved-if-field-is-blank-change-color/
Share on other sites

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

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.