Jump to content

Handling Error Message for Users?


mfleming

Recommended Posts

Hi.

 

I'm trying to display all the missing fields (errors) when the user hits SUBMIT.

 

My logic:

 

IF there is NO EMAIL THAN add $errortrack array = $errormsg

 

IF there is NO OLDPASSWORD THAN add $errortrack array = $errormsg[OLDPASS]

 

and so on.

 

At the end, Print ALL the Error messages on the form using

<?php foreach ( $errortrack as $key => $value) { 
                echo "<dt>$key:</dt>"; } ?>

 

The only thing it prints out is "0:" ever though there should be other errors.

 

What am I missing? 

 

Site Link http://www.fusionfashionhair.com/newpassform.php

My PHP Code:

<?php
session_start();
?>
<?php
$submit = $_POST['submit'];
// Form Data
$email = $_POST['email'];
$password_old = $_POST['password_old'];
$password_new = $_POST['password_new'];
$password_new_con = $_POST['password_new_con'];
$errorcount = 0;

$errormsg['Email'] = "Email Entered is Invalid";
$errormsg['OldPass'] = "Old Password Entered is Incorrect";
$errormsg['NewPass'] = "New Password Entered is Incorrect";
$errormsg['NewPassCon'] = "New Confirmed Password Entered is Incorrect";
$errormsg['SecCode'] = "Security Code is Incorrect";
$errormsg['NoErr'] = "No Errors, Continue";

$errortrack = array ($errormsg['NoErr']);

if ($_POST[submit]){
    if ($errorstop = "go") {
    $errorstop="go";
    while ($errorstop<>"stop") {
        // check for existance
      if ($email) {
            echo "True - Continue 1";
            echo "<p>----------</p>";
        } else {
            $errortrack = array ($errormsg['Email']);
            $errorcount++;
            $errorstop="stop";
        }
            
        // check for existance
      if ($password_old) {
            echo "True - Continue 2";
            echo "<p>----------</p>";
        } else {
            $errortrack = array ($errormsg['OldPass']);
            $errorcount++;
            $errorstop="stop";
        }        

        // check for existance
      if ($password_new) {
            echo "True - Continue 3";
            echo "<p>----------</p>";
        } else {
            $errortrack = array ($errormsg['NewPass']);
            $errorcount++;
            $errorstop="stop";
        }        

        // check for existance
      if ($password_new_con) {
            echo "True - Continue 4";
            echo "<p>----------</p>";
        } else {
            $errortrack = array ($errormsg['NewPassCon']);
            $errorcount++;
            $errorstop="stop";
        }            
        $errortrack = array ($errormsg="EVERYTHING IS OK");
        $errorstop="stop";
    }//End While Loop

    } else {
        while($errorcount>=0) {
            // Test display all error messages
            echo "<p>----------</p>";
            echo "<p>Error Count = '$errorcount'</p>";


        }
        die ("PLEASE FILL IN ALL FIELDS");
        
    }
}
?>

 

My Form Code with the PRINT ERROR:

    <form action='newpassform.php' method='post' id="regform">
      <fieldset>
        <legend>Change Password</legend>
        <p><?php foreach ( $errortrack as $key => $value) { 
                echo "<dt>$key:</dt>"; } ?></p>
        <p>
          <label for='email'>Email:</label>
          <input name='email' type='text' maxlength="25" value='<?php echo $email; ?>'/>
        </p>
        <p>
          <label for='password_old'>Old Password:</label>
          <input name='password_old' type='password' maxlength="32" />
        </p>
        <p>
          <label for='password_new'>New Password:</label>
          <input name='password_new' type='password' maxlength="32"/>
        </p>
        <p>
          <label for='password_new_con'>Confirm Password:</label>
          <input name='password_new_con' type='password' maxlength="32"/>
        </p>
        <p><span class="required">*</span> Note, username and password are case sensitive</p>
        <p>Forgot your password? <a href="forgot_password.php">Click Here</a></p>
        <p>Login <a href="login.php">Here</a></p>
       <h2>Security Check</h2>
      <p>Enter letters below exactly how they are displayed.  Letter are case sensitive. </p>
      <br />
      <img src="captcha.class.php?usefile=1" /> 
      <!--OR--> 
      <!--<img src="image.php" />-->
      
      <input id='user_code' name='user_code' type='text' size='10' >
      <p> </p>
        <input class="reset" type='reset' value='Cancel' name='reset'>
                <input class="submit" type='submit' value='Continue' name='submit'>
      </fieldset>
    </form>
    <!--End of Form--> 

 

Link to comment
https://forums.phpfreaks.com/topic/216318-handling-error-message-for-users/
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.