0

ヒアドキュメントステートメントを使用してHTMLを表示する完全に機能するスクリプトが12ありますが、たとえば$errors[field_name]、このほぼ同一のスクリプトは次のようなPOSTエラーになります

「通知: 未定義のインデックス: register.php の 162 行目の user_password」

8 文字以上が必要な場合にユーザーが 5 文字のパスワードを入力すると、検証関数が入力$errors['password']され、検証エラーと共にフォームが再表示されることになっています。

この Bootstrap スタイルのフォームに何が欠けているのかわかりません。配列はグローバルであり、$errorsエラーの表示を強制できるため、エラーが初期化されていることはわかっていますが、取得し続けます

「通知: 未定義のインデックス」

$fields = array( 'user_name', 'user_email', 'user_password', 'user_password2' );

function display_form($string = '')
{
    global $error_token, $cfg, $fields, $form, $errors, $s, $token, $validation_status;
    $error_message = '';
    switch($_SERVER['REQUEST_METHOD'])
    {
        Case 'POST':
            // validation failed, redisplay the form
            $autofocus = '';
            foreach($fields as $field){
                $$field = htmlentities(get_cgi_var($field), ENT_QUOTES, 'UTF-8');
                // wrap errors in Bootstrap alert markup
                $errors[$field] = !empty($errors[$field]) ? '<div class="alert alert-danger">'.htmlentities($errors[$field], ENT_QUOTES, 'UTF-8').'</div>' : '';
                // debug, force the premature display of errors.
                // echo !empty($errors[$field]) ? '<div class="alert alert-danger">'.htmlentities($errors[$field], ENT_QUOTES, 'UTF-8').'</div>' : '<p>empty</p>';
            }
            break;
        Case 'GET':
        default:
            $autofocus = 'autofocus';
            foreach($fields as $field){
                $$field = '';
                $errors[$field] = '';
            }
            $error_token = '';
            break;
    };
    foreach($fields as $field){
        $validation_status[$field] = empty($errors[$field]) ? ' has-success' : ' has-error';
    }
    $self = SELF;

print<<<_HTML_
<div class="col-lg-6">
  <div class="panel panel-primary">
    <div class="panel-heading">Registration</div>
    <div class="panel-body">
      $string
      $error_message
      <form name="form1" id="form1" action="$self" class="form-horizontal" role="form" method="POST">
      <fieldset>
      $error_token
      $errors[user_name]
      <div class="row form-group$validation_status[user_name]">
        <label for="user_name" class="col-lg-3 control-label">Name</label>
        <div class="col-lg-9">
          <input type="text" name="user_name" id="user_name" value="$user_name" maxlength="255" $autofocus required placeholder="Your First &amp; Last Name" title="Your First &amp; Last Name" autocomplete="on" class="form-control">
        </div>
      </div>
      $errors[user_email]
      <div class="row form-group$validation_status[user_email]">
        <label for="user_email" class="col-lg-3 control-label">Email</label>
        <div class="col-lg-9">
          <input type="email" name="user_email" id="user_email" value="$user_email" maxlength="255" required placeholder="Your Email Address" autocomplete="on" class="form-control">
        </div>
      </div>
      $errors[user_password]
      <div class="row form-group$validation_status[user_password]">
        <label for="user_password" class="col-lg-3 control-label">Password</label>
        <div class="col-lg-9">
          <input type="text" name="user_password" id="user_password" value="$user_password" maxlength="255" required placeholder="Password or Passphrase" autocomplete="on" class="form-control">
          <p class="help-block">Case sensitive password containing 8+ characters or a phrase containing 3-5 words</p>
        </div>
      </div>
      $errors[user_password2]
      <div class="row form-group$validation_status[user_password2]">
        <label for="user_password2" class="col-lg-3 control-label">Password</label>
        <div class="col-lg-9">
          <input type="text" name="user_password2" id="user_password2" value="$user_password2" maxlength="255" required placeholder="Re-enter Password or Passphrase" autocomplete="on" class="form-control">
        </div>
      </div>
      <div class="row form-group">
        <label for="submit_button" class="col-lg-3 control-label">&nbsp;</label>
        <div class="col-lg-9 text-center">
          <input type="hidden" name="token" value="$token">
          <input type="submit" name="submit_button" id="submit_button" value="Submit" onClick="return captcha_validation(this.form);" class="btn btn-primary">
        </div>
      </div>
      </fieldset>
      </form>
      </div><!-- /panel-body -->
      <div class="panel-footer text-center">&nbsp;</div>
  </div><!-- /panel -->
</div><!-- /col -->
<div class="col-lg-6">
  <div class="well">unused column</div>
</div><!-- /col -->
_HTML_;
};
4

1 に答える 1