sigmahokies Posted May 22, 2018 Share Posted May 22, 2018 Hi everyone, I am trying to have "require" label on form. If someone did not select the option on list, then "require" label will appear in form after submit. Seem my code isn't work. what did I do wrong? <?php$buzz = $buzz2 = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { if (empty($_POST['select'])) { $buzz = "<h2><color color='red'> >- </color></h2>"; $buzz2 = "<h2><color='red'> -< </color></h2>"; }} ?><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>XXXXXX</title> <link href="default.css" rel="stylesheet" type="text/css"></head><body><fieldset><h1>XXXXXXX</h1> <table> <form action="login.php" method="post"> <select name="select"> <?php echo $buzz ?><option value="" >Please select the level</option><?php echo $buzz2 ?> <option value="Administrator">Administrator</option> <option value="License">License</option> <option value="Scorer">Scorer</option> </select> <caption>Please login to enter the site below:</caption> <tr><td>Username:</td><td class="td"><input type="text" name="user"></td></tr> <tr><td>Password:</td><td class="td"><input type="password" name="password"></td></tr> <tr><td colspan="2"><input type="submit" name="submitted" value="Login"></td></tr> </form> </table></fieldset></body></html> Thanks for helping Gary Taylor Link to comment Share on other sites More sharing options...
taquitosensei Posted May 22, 2018 Share Posted May 22, 2018 I think your $buzz and $buzz2 need to come before and after the <select>'s and then you need to make the blank option selected. <?php echo ($buzz)?$buzz:""; ?> <select name="select"> <option value="" <?php echo ($buzz)?"selected":""; ?>>Please select the level</option> <option value="Administrator">Administrator</option> <option value="License">License</option> <option value="Scorer">Scorer</option> <select> <?php echo ($buzz2)?$buzz2:""; ?> Hi everyone, I am trying to have "require" label on form. If someone did not select the option on list, then "require" label will appear in form after submit. Seem my code isn't work. what did I do wrong? <?php$buzz = $buzz2 = ""; if ($_SERVER['REQUEST_METHOD'] == "POST") { if (empty($_POST['select'])) { $buzz = "<h2><color color='red'> >- </color></h2>"; $buzz2 = "<h2><color='red'> -< </color></h2>"; }} ?><!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>XXXXXX</title> <link href="default.css" rel="stylesheet" type="text/css"></head><body><fieldset><h1>XXXXXXX</h1> <table> <form action="login.php" method="post"> <select name="select"> <?php echo $buzz ?><option value="" >Please select the level</option><?php echo $buzz2 ?> <option value="Administrator">Administrator</option> <option value="License">License</option> <option value="Scorer">Scorer</option> </select> <caption>Please login to enter the site below:</caption> <tr><td>Username:</td><td class="td"><input type="text" name="user"></td></tr> <tr><td>Password:</td><td class="td"><input type="password" name="password"></td></tr> <tr><td colspan="2"><input type="submit" name="submitted" value="Login"></td></tr> </form> </table></fieldset></body></html> Thanks for helping Gary Taylor Link to comment Share on other sites More sharing options...
sigmahokies Posted May 22, 2018 Author Share Posted May 22, 2018 Seem it doesn't work Link to comment Share on other sites More sharing options...
Barand Posted May 22, 2018 Share Posted May 22, 2018 you could try using the "required" property <select name="select" required> <option value="">Please select the level</option> <option value="Administrator">Administrator</option> <option value="License">License</option> <option value="Scorer">Scorer</option> <select> Link to comment Share on other sites More sharing options...
sigmahokies Posted May 22, 2018 Author Share Posted May 22, 2018 seem it works, not need to have php to remind... Thank you, Barand Gary Taylor Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.