Jump to content

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

Edited by sigmahokies
Link to comment
https://forums.phpfreaks.com/topic/307296-valdiation/
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
https://forums.phpfreaks.com/topic/307296-valdiation/#findComment-1558551
Share on other sites

  • Solution

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
https://forums.phpfreaks.com/topic/307296-valdiation/#findComment-1558553
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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