Jump to content

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

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.