Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post

    PLEASE HELP! Form not showing!

    Hi all. can someone tell me why my form says "validate" and "processing" instead of showing the correct form for my login?

    code:

    top of login.php:
    PHP Code:
    <?php 
     error_reporting
    (E_ALL); 
     
    ini_set("display_errors"1); 
    ?>
    <?php
    session_start
    ();
    ?>
    <?php
    require("formvalidation.php");
    ?>
    formvalidation.php:
    PHP Code:
    <?php
    function validate_form(){ 
    $ListErrors = array();
    echo 
    "<br>validate<br>\n";

    if (isset( 
    $_POST['user'] )) $input1 $_POST['user'];
    if (isset( 
    $_POST['pass'] )) $input2 $_POST['pass'];

    if (
    $input1==1
    $ListErrors["user"]="You forgot to enter a username";
    if (
    $input2==2
    $ListErrors["pass"]="You forgot to enter a password";

    return 
    $ListErrors
    }


    function 
    show_form(){

    if (
    $num_args func_num_args()>0)
    $Errors=func_get_arg(0);


    echo 
    "                <form name=\"login\" id=\"login\" action=\"".$_SERVER['PHP_SELF']."\" method=post>\n";
    echo 
    "                </p>\n";
    echo 
    "                <p>\n";
    echo 
    "                          <div name=\"login1\" id=\"login1\"></div>\n";
    echo 
    "                User (e-mail):<br/><input type=\"text\" value=\"\" name=\"user\" id=\"user\"/><br/>\n";
    echo 
    "                Password:<br/><input type=\"text\" value=\"\" name=\"pass\" id=\"pass\"/><br/><br/>\n";
    echo 
    "                          <input type=\"hidden\" name=\"_submit_check\" value=\"1\"/>\n";
    echo 
    "                <input type=\"submit\" name=\"loginform\" value=\"Login\"/></p>\n";
    echo 
    "                          </form>\n";
    echo 
    "                          </div>\n";

    }

    function 
    process_form(){
    echo 
    "processing<br>\n";
    //run the control

    }
    ?>
    code inside login.php that shows the form:

    PHP Code:
    <?php
    if (array_key_exists('_submit_check',$_POST)) {
         
    // If validate_form() returns errors, pass them to show_form()
         
    if ($form_errors validate_form()) {
             
    show_form($form_errors);
         } else {
             
    // The submitted data is valid, so process it
             
    process_form();
         }
    } else {
         
    // The form wasn't submitted, so display
         
    show_form();
    }
    ?>
    If u need the login form, I can give it to u

    ANY help is GREATLY appreciated!

    Thanks!

    Rez~
    Last edited by ShadowIce; 10-13-2009 at 10:38 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    it basically shows the actual form, but what i mean by 'it doesn't show the form', is that it wont show the errors even when there is 1

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I don't see any code to echo the errors in function show_form.
    Are you a Help Vampire?

  • #4
    Regular Coder
    Join Date
    Apr 2009
    Posts
    264
    Thanks
    24
    Thanked 1 Time in 1 Post
    Here's what I have now. It's not returning anything but an error ><

    formvalidation.php:

    PHP Code:
    <?php
    function validate_form(){ 
    $ListErrors = array();
    echo 
    "<br>validate<br>\n";

    if (isset( 
    $_POST['user'] )) $input1 $_POST['user'];
    if (isset( 
    $_POST['pass'] )) $input2 $_POST['pass'];

    if (
    $input1==1
    $ListErrors["user"]="You forgot to enter a username";
    if (
    $input2==2
    $ListErrors["pass"]="You forgot to enter a password";

    return 
    $ListErrors;

    }


    function 
    show_form(){

    if (
    $num_args func_num_args()>0){
    $Errors=func_get_arg(0);
    $login true;

    echo 
    "                <form name=\"login\" id=\"login\" action=\"".$_SERVER['PHP_SELF']."\" method=post>\n";
    echo 
    "                </p>\n";
    echo 
    "                <p>\n";
    echo 
    "                          <div name=\"login1\" id=\"login1\"></div>\n";
    echo 
    "                User (email):<br/><input type=\"text\" value=\"\" name=\"user\" id=\"user\"/><br/>\n";
    echo 
    "                Password:<br/><input type=\"text\" value=\"\" name=\"pass\" id=\"pass\"/><br/><br/>\n";
    echo 
    "                          <input type=\"hidden\" name=\"_submit_check\" value=\"1\"/>\n";
    echo 
    "                <input type=\"submit\" name=\"loginform\" value=\"Login\"/></p>\n";
    echo 
    "                          </form>\n";
    echo 
    "                          </div>\n";

    }else{

    $login false;

    echo 
    "                <form name=\"login\" id=\"login\" action=\"login1.php\" method=post>\n";
    echo 
    "                </p>\n";
    echo 
    "                <p>\n";
    echo 
    "                          <div name=\"login1\" id=\"login1\"></div>\n";
    echo 
    "                User (email):<br/><input type=\"text\" value=\"\" name=\"user\" id=\"user\"/><br/>\n";
    echo 
    "                Password:<br/><input type=\"text\" value=\"\" name=\"pass\" id=\"pass\"/><br/><br/>\n";
    echo 
    "                          <input type=\"hidden\" name=\"_submit_check\" value=\"1\"/>\n";
    echo 
    "                <input type=\"submit\" name=\"loginform\" value=\"Login\"/></p>\n";
    echo 
    "                          </form>\n";
    echo 
    "                          </div>\n";

    $Error validate_form();

    echo 
    $Error;

    }

    }

    function 
    process_form(){
    echo 
    "processing<br>\n";
    //run the form if no errors are found

    }
    ?>
    login.php:
    PHP Code:
    <?php
    if (array_key_exists('_submit_check',$_POST)) {
         
    // If validate_form() returns errors, pass them to show_form()
         
    if ($form_errors validate_form()) {
             
    show_form($form_errors);
         } else {
             
    // The submitted data is valid, so process it
             
    process_form();
         }
    } else {
         
    // The form wasn't submitted, so display
         
    show_form();
    }
    ?>
    also, $login is defined in login1.php, which is where it SHOULD take u if there are no errors

    I need it to return the correct error depending on which input box the user didnt enter information into. (user or pass input box)
    Last edited by ShadowIce; 10-14-2009 at 12:58 AM.

  • #5
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    What's the error?
    Are you a Help Vampire?


  •  

    Posting Permissions

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