php form not working with IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jbrown007
    New Member
    • Dec 2009
    • 3

    php form not working with IE

    Have a form that works with FF, Chrome but not working with any version of IE.



    the contact.php script is as follows:

    Code:
    <?php
    /* Set e-mail recipient */
    $myemail  = "rentals@example.com";
    
    
    /* Check all form inputs using check_input function */
    $group = check_input($_POST['group']);
    $yourname = check_input($_POST['yourname']);
    $address = check_input($_POST['address']);
    $city = check_input($_POST['city']);
    $state = check_input($_POST['state']);
    $zip = check_input($_POST['zip']);
    $phone = check_input($_POST['phone']);
    $email = check_input($_POST['email'], "Enter your email address");
    $arrival_date = check_input($_POST['arrival_date']);
    $departure_date = check_input($_POST['departure_date']);
    $local_lodging = check_input($_POST['local_lodging']);
    $num_days = check_input($_POST['num_days']);
    $name1 = check_input($_POST['name1']);
    $age1 = check_input($_POST['age1']);
    $height1 = check_input($_POST['height1']);
    $weight1 = check_input($_POST['weight1']);
    $sport_equip1 = check_input($_POST['1sport_equi1p']);
    $sport_ski_size1 = check_input($_POST['sport_ski_size1']);
    $demo_equip1 = check_input($_POST['demo_equip1']);
    $demo_ski_model1 = check_input($_POST['demo_ski_model1']);
    $demo_ski_size1 = check_input($_POST['demo_ski_size1']);
    $shoe_size1 = check_input($_POST['shoe_size1']);
    $board_equip1 = check_input($_POST['board_equip1']);
    $board_size1 = check_input($_POST['board_size1']);
    $jr_equip1 = check_input($_POST['jr_equip1']);
    $jr_ski_size1 = check_input($_POST['jr_ski_size1']);
    $skier_type1 = check_input($_POST['skier_type1']);
    $comment1 = check_input($_POST['comment1']);
    $name2 = check_input($_POST['name2']);
    $age2 = check_input($_POST['age2']);
    $height2 = check_input($_POST['height2']);
    $weight2 = check_input($_POST['weight2']);
    $sport_equip2 = check_input($_POST['sport_equip2']);
    $sport_ski_size2 = check_input($_POST['sport_ski_size2']);
    $demo_equip2 = check_input($_POST['demo_equip2']);
    $demo_ski_model2 = check_input($_POST['demo_ski_model2']);
    $demo_ski_size2 = check_input($_POST['demo_ski_size2']);
    $shoe_size2 = check_input($_POST['shoe_size2']);
    $board_equip2 = check_input($_POST['board_equip2']);
    $board_size2 = check_input($_POST['board_size2']);
    $jr_equip2 = check_input($_POST['jr_equip2']);
    $jr_ski_size2 = check_input($_POST['jr_ski_size2']);
    $skier_type2 = check_input($_POST['skier_type2']);
    $comment2 = check_input($_POST['comment2']);
    $name3 = check_input($_POST['name3']);
    $age3 = check_input($_POST['age3']);
    $height3 = check_input($_POST['height3']);
    $weight3 = check_input($_POST['weight3']);
    $sport_equip3 = check_input($_POST['sport_equip3']);
    $sport_ski_size3 = check_input($_POST['sport_ski_size3']);
    $demo_equip3 = check_input($_POST['demo_equip3']);
    $demo_ski_model3 = check_input($_POST['demo_ski_model3']);
    $demo_ski_size3 = check_input($_POST['demo_ski_size3']);
    $shoe_size3 = check_input($_POST['shoe_size3']);
    $board_equip3 = check_input($_POST['board_equip3']);
    $board_size3 = check_input($_POST['board_size3']);
    $jr_equip3 = check_input($_POST['jr_equip3']);
    $jr_ski_size3 = check_input($_POST['jr_ski_size3']);
    $skier_type3 = check_input($_POST['skier_type3']);
    $comment3 = check_input($_POST['comment3']);
    $name4 = check_input($_POST['name4']);
    $age4 = check_input($_POST['age4']);
    $height4 = check_input($_POST['height4']);
    $weight4 = check_input($_POST['weight4']);
    $sport_equip4 = check_input($_POST['sport_equip4']);
    $sport_ski_size4 = check_input($_POST['sport_ski_size4']);
    $demo_equip4 = check_input($_POST['demo_equip4']);
    $demo_ski_model4 = check_input($_POST['demo_ski_model4']);
    $demo_ski_size4 = check_input($_POST['demo_ski_size4']);
    $shoe_size4 = check_input($_POST['shoe_size4']);
    $board_equip4 = check_input($_POST['board_equip4']);
    $board_size4 = check_input($_POST['board_size4']);
    $jr_equip4 = check_input($_POST['jr_equip4']);
    $jr_ski_size4 = check_input($_POST['jr_ski_size4']);
    $skier_type4 = check_input($_POST['skier_type4']);
    $comment4 = check_input($_POST['comment4']);
    
    
    /* If e-mail is not valid show error message */
    if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
    {
        show_error("E-mail address not valid");
    }
    
    
    /* Let's prepare the message for the e-mail */
    $message = "What is up your rentalness!
    
    Everybody wants some, this person wants some too:
    _______________________________________
    Group Name: $group
    
    Name: $yourname
    Contact Address: $address
    City: $city
    State: $state
    Zip Code: $zip
    Daytime Phone:  $phone
    Contact E-mail: $email
    Arrival Date: $arrival_date
    Departure Date: $departure_date
    Local Accomodations: $local_lodging
    Number of days skiing: $num_days
    __________________________________________
    RENTER #1
       Name: $name1
       Birth Date:  $age1
       Height (ft/in): $height1
       Weight (lbs): $weight1
    SPORT EQUIPMENT
       Package Type: $sport_equip1
       Sport Ski Size: $sport_ski_size1
       Shoe size: $shoe_size1
    DEMO SKIS
       Package Type: $demo_equip1
       Demo ski model: $demo_ski_model1
       Demo Ski size: $demo_ski_size1
       Shoe size: $shoe_size1
    SNOWBOARD
       Package Type: $board_equip1
       Board size: $board_size1
       Shoe size: $shoe_size1
    KID'S EQUIPMENT (12 and under)
       Junior Pakage: $jr_equip1
       Ski Length: $jr_ski_size1
       Shoe size: $shoe_size1
    Skier Type: $skier_type1
    Comments: $comment1
    ___________________________________
    RENTER #2
       Name: $name2
       Birth Date:  $age2
       Height (ft/in): $height2
       Weight (lbs): $weight2
    SPORT EQUIPMENT
       Package Type: $sport_equip2
       Sport Ski Size: $sport_ski_size2
       Shoe size: $shoe_size2
    DEMO SKIS
       Package Type: $demo_equip2
       Demo ski model: $demo_ski_model2
       Demo Ski size: $demo_ski_size2
       Shoe size: $shoe_size2
    SNOWBOARD
       Package Type: $board_equip2
       Board size: $board_size2
       Shoe size: $shoe_size2
    KID'S EQUIPMENT (1 and under)
       Junior Pakage: $jr_equip2
       Ski Length: $jr_ski_size2
       Shoe size: $shoe_size2
    Skier Type: $skier_type2
    Comments: $comment2
    ________________________________________
    RENTER #3
       Name: $name3
       Birth Date:  $age3
       Height (ft/in): $height3
       Weight (lbs): $weight3
    SPORT EQUIPMENT
       Package Type: $sport_equip3
       Sport Ski Size: $sport_ski_size3
       Shoe size: $shoe_size3
    DEMO SKIS
       Package Type: $demo_equip3
       Demo ski model: $demo_ski_model3
       Demo Ski size: $demo_ski_size3
       Shoe size: $shoe_size3
    SNOWBOARD
       Package Type: $board_equip3
       Board size: $board_size3
       Shoe size: $shoe_size3
    KID'S EQUIPMENT (12 and under)
       Junior Pakage: $jr_equip3
       Ski Length: $jr_ski_size3
       Shoe size: $shoe_size3
    Skier Type: $skier_type3
    Comments: $comment3
    _____________________________
    RENTER #4
       Name: $name4
       Birth Date:  $age4
       Height (ft/in): $height4
       Weight (lbs): $weight4
    SPORT EQUIPMENT
       Package Type: $sport_equip4
       Sport Ski Size: $sport_ski_size4
       Shoe size: $shoe_size4
    DEMO SKIS
       Package Type: $demo_equip4
       Demo ski model: $demo_ski_model4
       Demo Ski size: $demo_ski_size4
       Shoe size: $shoe_size4
    SNOWBOARD
       Package Type: $board_equip4
       Board size: $board_size4
       Shoe size: $shoe_size4
    KID'S EQUIPMENT (12 and under)
       Junior Pakage: $jr_equip4
       Ski Length: $jr_ski_size4
       Shoe size: $shoe_size4
    Skier Type: $skier_type4
    Comments: $comment4
    
    
    End of message
    ";
    
    $subject = "Rental Reservation";
    
    /* Send the message using mail() function */
    mail($myemail, $subject, $message);
    
    /* Redirect visitor to the thank you page */
    header('Location: http://www.tetonvillagesports.com/thanks.html');
    exit();
    
    /* Functions we used */
    function check_input($data, $problem='')
    {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        if ($problem && strlen($data) == 0)
        {
            show_error($problem);
        }
        return $data;
    }
    
    function show_error($myError)
    {
    ?>
        <html>
        <body>
    
        <b>Please correct the following error:</b><br />
        <?php echo $myError; ?>
    
        </body>
        </html>
    <?php
    exit();
    }
    ?>


    Any thoughts would be appreciated
    Last edited by Atli; Dec 22 '09, 07:05 PM. Reason: Added [code] tags and replaced real email with an example.
  • jbrown007
    New Member
    • Dec 2009
    • 3

    #2
    Never mind I figured it out.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hey.

      How exactly is it now working? Can you elaborate on that please.

      It would also help to see the HTML form (or a part of it, at least) that triggers this code. Since this is a browser issue, the problem is most likely not in the PHP code, but rather in the HTML form.


      Also, since you have a LOT of input fields that you need to check...
      Rather than type them out like that, manually writing each one into the check_input function and creating a global variable for each of them, you might want to try a more dynamic way, using arrays:
      [code=php]<?php
      // Set up a list of fields and their respective problem texts.
      $fields = array(
      'name' => 'Enter a valid name!',
      'email' => 'Your email address is invalid!',
      'field3' => '',
      'etc...' => ''
      );

      // An array to hold the data for the fields.
      $data = array();

      // Go through the field list and check the input for each of them.
      foreach($fields as $_name => $_problem) {
      $data[$_name] = check_input($_P OST[$_name], $_problem);
      }

      // Do something with the data
      $text = <<<TEXT
      Some string that you would inject the data into:
      Name: {$data['name']}
      Email: {$data['email']}
      Field3: {$data['field3']}
      TEXT;
      ?>[/code]
      This way you don't have to manually use the function for each field, and it's a little more organized. You could even pull the field list from another source. (Not that that's necessarily a good idea :P)

      And by using the $data array like that, you don't clutter the global scope with random variables, which is good. (Keeping the global scope clear is always best)

      Comment

      • jbrown007
        New Member
        • Dec 2009
        • 3

        #4
        Thanks for the input, I appreciate the help. The form is located at



        The problem was resolved after I finally realized the Submit button was outside of the form tags. Everything (other than terrible coding) is now going great.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Glad to hear that.
          It always seems that these sort of minor oversights cause the biggest problems :)

          Comment

          Working...