SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Displayed error message counting as error after correction

    Greetings everyone
    hope someone can offer a hand at this.

    I have coded a form to echoe errors to the same page. If data is valid ,it is exuted and a thank you message is echoed on the final page.

    My problem is that if an error message is displayed and then the user corrects the input,the script still considers the now corrected displayed error message to be an error and submits the form to the same page instead of moving it to the final page.

    Can anyone help me how to tell the script to look for the error in the form and not above it where it is displayed ?

    PHP Code:

    if (count($errmsg)>0) {
    ?>
    <FORM action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="form1">
    <?
    }
    else {
    ?>
    <FORM action="finalpage.php" method="post" enctype="multipart/form-data" name="finalpage">
    <?
    }

  2. #2
    SitePoint Wizard bronze trophy Kailash Badu's Avatar
    Join Date
    Nov 2005
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How is $errmsg populated ?
    I think you need to go through a tutorial on form processing.

  3. #3
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $errmsg = array(); 
    then something like this:
    PHP Code:
    if(trim($First_Name) == '')
       {
          
    $errmsg[] = 'Error:Please enter your first name';
       }
    etc.....

    if (
    count($errmsg)>0){
         foreach(
    $errmsg as $error)
            echo 
    "$error<br>\n"
    When the user corrects an input that is pointed out in red above the form,it passes validation.However,the if/else statement(above) relies on the displayed error message.
    After user corrects the input and hits submit,the same page loads without error message this time,but user has to hit submit again to go to final page.(coz so long as an error is displayed,the conditional above will set it to same page till there's no error message displayed)

    I want as soon as input is corrected,the if/else statement picks up that upon hitting submit button and page goes to final page,instead of loading again with no errors,waiting for another hit of submit button.

  4. #4
    SitePoint Zealot Tikila's Avatar
    Join Date
    Jun 2007
    Location
    Toronto
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do I need javascript to accomplish this?
    php needs to interact with the server and then back again to load the page,js does not do that.So do you think I should implement my if/else with javascript instead ?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •