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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    php array taking 2 form submits to work

    Hello and thank you in advance for taking a look at this.

    This form handling script uses php redux to send the variables to itself.

    I've got this little array setup so that if someone forgets to enter a required field, it will only show the fields missed instead of throwing the whole form back on screeen.

    However, it takes 2 erroneous submissions to display all of them!

    If the form is submitted with none of these fields filled in,
    it simply returns the email field. Then when that is filled
    and submitted, it shows all three (including the email again!).

    here is the code:

    PHP Code:
        if (!eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",stripslashes(trim($_POST['emailaddress'])))) {
            
    $form_errors["email"] = 'Please enter a valid Email Address: <input type="text" size="35" name="emailaddress" /><br />';
        }
        if (!isset(
    $_POST['name'])){
            
    $form_errors["name"] = 'Please fill in your name: <input type="text" size="45" name="name" /><br />';
        }
        if (!isset(
    $_POST['phone'])){
            
    $form_errors["phone"] = 'Enter a valid phone number: <input type="text" size="25" name="phone" /><br />';
        } 

        
        if (
    is_array($form_errors)) {
            while(list(
    $key$val) = each($form_errors)) {
                echo 
    $val;
                echo 
    "<br />\n";
            }
            echo 
    '<input type="submit" name="action" value="send" style="border:1px solid #888; background:#e0e0e0; margin-right:300px;" />';
        } else {
                do 
    other stuff... 

    See it in (broken) action here: http://www.elaborateforms.com/app_beta2.php

    Again thank you in advance,
    Brett
    Last edited by curious_coder; 06-01-2007 at 11:46 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    At a glance it seems like your "if (!isset($_POST['name']))" condition isn't quite what you want-- That variable will exist and return true even if the user doesn't enter anything in the field.

    There's other stuff happening but that's what jumped out at me.

    Just curious-- why are you doing the form this way? IMO it's not intuitive to make fields disappear if they were filled in correctly-- maybe it's because it's not a common web form behavior...


  •  

    Posting Permissions

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