1.11M Members

changing border in php code

 
0
 

i have a form and inside i have one field and one button. when user hit submit button a php script runs.

in php script i am checking error. ex name is too short etc..

now i want to add a red border only if there is a error. if i get to echo"Error - first name..." than i want to set that input field border red. i am not sure how can i do this. any ideas?

index.php

<?php 
    if(isset($_POST['button'])) 
     {
         //check errors
        if((strlen($_POST['f_input']) < 2))
        {
            echo "Error - first name is too short!";
        }
        else
        {
           ....
        }
     }
?>

<form action='index.php' method='POST'>
  <input type='field' placeholder='first name'  id='f_field' name='f_input'  />
  ...
   <button type="submit" id='button' name="button" >submit</button>
</form>
 
1
 

Use css,

if(strlen($_POST['f_input'])<2))
{
   echo"<input type='text' class='abc' value='<?php $_POST['f_input'] ?>'>";
   }elseif(strlen($_POST['f_input']>2)){

    echo"<input type='text' class='def' value='<?php $_POST['f_input'] ?>'>";
    }

so your css would be like

.abc{
border-color:red;
}
.def{
border-color:black;
}
Question Answered as of 1 Year Ago by TonyG_cyprus
 
0
 

ah thanks

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article