Jump to content


Empty field in an application

  • Please log in to reply
1 reply to this topic

#1 moonlightsonata

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 16 September 2006 - 04:52 PM

Im just starting in php so i hope you can help me guys...

How can i do this in php?
I have this fields that you need to fill up and theres a submit button

Now what i want to do is that if one of the fields was not fill up or is empty and
when the submit button is clicked you cannot proceed instead you will go back to the original application form(the fields) and the field that was not answered will be highlighted and will have an asterisk beside it while other fields who have answers will retain.

Just like when you are filling up or registering in yahoo for yahoo mail.

#2 Barand

  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 16 September 2006 - 07:02 PM

Here's one way
// initialise variables
$user = $pwd = '';

// set default field bg colors
$bgcol = array (
    'user' => '#FFFFFF',
    'pwd'  => '#FFFFFF'
if (isset($_POST['user'])) {
    $user = $_POST['user'];
    if (!$user) $bgcol['user'] = '#FFCCCC';
    $pwd = $_POST['pwd'];
    if (!$pwd) $bgcol['pwd'] = '#FFCCCC';

// check that they were filled in
if ($user && $pwd) {

    // OK to process the input
    echo "User : $user<br>Password : $pwd<br>" ;

else {      
    // one or more is empty so display the form again
    echo "<form method='post'>\n";
    echo "Enter username ";
    echo "<input type='text' name='user' value='$user' style='background-color:{$bgcol['user']}'>"; 
    echo "<br>Enter password ";
    echo "<input type='text' name='pwd' value='$pwd' style='background-color:{$bgcol['pwd']}'>";

    echo "<br><input type='submit' name='submit' value='Submit'>";
    echo "</form>\n";

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received


|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users