1

アクションを実行するために、html フォーム内のテキスト ボックスに入力できるようにしたい値のリストがあります。アクションは、エンド ユーザーを特定の Web ページに誘導します。しかし、エンドユーザーには特定の値のみを入力してもらいたいです。他の入力を許可することもできますが、間違ったコードを入力したという通知/警告が表示されます。

あらかじめ決められた 3 つの値のリストは、次のようになります。

GGG01、OOO03、MTM02

先ほど述べたように、エンド ユーザーは何でも入力できるようにする必要がありますが、これら 3 つのコードのいずれかを入力した場合にのみ、特定の Web ページに移動する必要があります。検証スクリプトを試しましたが、何も機能していないようです。ここで何かが欠けていますが、とても簡単だと思います。

これが私が試したことですが、パスワードフィールドが正しく機能していません。助けてください。前もって感謝します。

<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE html
   PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>
      Example for Validator
    </title>
    <style type="text/css" xml:space="preserve">
BODY, P,TD{ font-family: Arial,Verdana,Helvetica, sans-serif; font-size: 10pt }
A{font-family: Arial,Verdana,Helvetica, sans-serif;}
B { font-family : Arial, Helvetica, sans-serif; font-size : 12px;   font-weight : bold;}
.error_strings{ font-family:Verdana; font-size:10px; color:#660000;}
</style><script language="JavaScript" src="gen_validatorv4.js"
    type="text/javascript" xml:space="preserve"></script>
  </head>
  <body>
    <form action="" name="myform" id="myform">
      <table cellspacing="2" cellpadding="2" border="0">
        <tr>
          <td align="right">
            First Name
          </td>
          <td>
            <input type="text" name="FirstName" />
          </td>
        </tr>
        <tr>
          <td align="right">
            Last Name
          </td>
          <td>
            <input type="text" name="LastName" />
          </td>
        </tr>
        <tr>
          <td align="right">
            EMail
          </td>
          <td>
            <input type="text" name="Email" />
          </td>
        </tr>
        <tr>
          <td align="right">
            Password
          </td>
          <td>
            <input type="text" name="pwd1" />
          </td>
        </tr>
        <tr>
          <td align="right">
            Address
          </td>
          <td>
            <textarea cols="20" rows="5" name="Address"></textarea>
          </td>
        </tr>
        <tr>
          <td align="right">
            Country
          </td>
          <td>
            <select name="Country">
            <option value="" selected="selected">
              [choose yours]
            </option>
            <option value="008">
              Albania
            </option>
            <option value="012">
              Algeria
            </option>
            <option value="016">
              American Samoa
            </option>
            <option value="020">
              Andorra
            </option>
            <option value="024">
              Angola
            </option>
            <option value="660">
              Anguilla
            </option>
            <option value="010">
              Antarctica
            </option>
            <option value="028">
              Antigua And Barbuda
            </option>
            <option value="032">
              Argentina
            </option>
            <option value="051">
              Armenia
            </option>
            <option value="533">
              Aruba
            </option></select>
          </td>
        </tr>
        <tr>
          <td align="right"></td>
          <td>
            <div id="myform_errorloc" class="error_strings">
            </div>
          </td>
        </tr>
        <tr>
          <td align="right"></td>
          <td>
            <input type="submit" value="Submit" />
          </td>
        </tr>
      </table>
    </form><script language="JavaScript" type="text/javascript"
    xml:space="preserve">//<![CDATA[
//You should create the validator only after the definition of the HTML form

    function DoCustomValidation()
{
  var frm = document.forms["myform"];
  if(frm.pwd1.value != frm.pwd2.value)
  {
    sfm_show_error_msg('The Password and verified password does not match!',frm.pwd1);
    return false;
  }
  else
  {
    return true;
  }
}

  frmvalidator.setAddnlValidationFunction(DoCustomValidation);
//]]></script>
  </body>
</html>
4

1 に答える 1

0

I'm taking it that we're looking for options without connecting to a database (that would make the answer longer). To start you off on a direction and one particular option (which might not be the most favorable or efficient option for your situation):

Firstly, form tag should have a method attribute.

<form action="confirm.php" method="POST" name="myform" id="myform">

then you can access it and make conditional statements later on. For example, if a person typed in a certain word that you wanted in the LastName section and submitted it, you can let it go confirm.php which would include the following script (which would evaluate if the user put in a certain value or not, and depending on the value, the user would be redirected to a different page):

if ($_POST['LastName']=="GGG01"){
    header("nameofnewwebsite.php");
}else{
    header("nameofanotherwebsite.php");
}
于 2013-05-15T03:20:11.457 に答える