Jump to content

Valdiation


sigmahokies

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.