moonlightsonata Posted September 16, 2006 Share Posted September 16, 2006 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 buttonNow what i want to do is that if one of the fields was not fill up or is empty andwhen 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.Thanks Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2006 Share Posted September 16, 2006 Here's one way[code]<?php// 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 inif ($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";}?>[/code] Quote Link to comment 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.