Jump to content

PHP form not submitting on IE 8, But does submit on Firefox and Chrome


jeweline

Recommended Posts

Hi All,

 

I am a newbie to this forum and a newbie to scripting. In fact this is my first type trying to make a form work. I've created a PHP contact form that when the submit button is clicked, I want it to send an e-mail to a certain address. Thanks so much for taking the time to look at this and help me! I'm so confused and frustrated! :banghead: Any help offered would be greatly appreciated. Thanks!

 

I created the form in Dreamweaver. I first added code for server-side verification of the fields and then I used Dreamweaver's Spry Validation widgets to add client-side verification of the form elements.

 

In Firefox and Google Chrome, when I test the form by correctly filling out the different form elements and clicking the submit button:

  • the form gets submitted
    the "thank you" message correctly displays
    and I receive an e-mail in my mailbox

The problem is with Internet Explorer 8. When I test the form by correctly completing the various form elements and clicking the submit button:

 

The form doesn't get submitted because

  • I see the following statement "Sorry, there was a problem sending your message. Please try later." This statement displays because part of an "If-then-else" statement failed. It is part of the client-side verification code I created
    Since, the form wasn't submitted, I don't get the resulting e-mail.

 

I really don't know enough about PHP to debug. All I can figure is that for some reason IE thinks the $_POST and $mailSent variables are empty, so it displays the "sorry, there was a problem" error message.

 

Here's a link to the form I'm testing:

http://www.buypuresilverbullion.com/silverlinemarket2/contactus.php

 

[b]Here's the code I'm using in the contact form page to display either error messages or a confirmation message:[/b]

 

<?php
if ($_POST && isset($missing) && !empty($missing)) {
?>
  <p class="warning2"><strong>Please complete the missing item(s) indicated.</strong></p>
<?php
} elseif ($_POST && !$mailSent) {
?>
  <p class="warning2">Sorry, there was a problem sending your message. Please try later.</p>
<?php
} elseif ($_POST && $mailSent) {
?>
  <p class="acknowledgement"><strong>Thanks so much for taking the time to send us a note! We’ve received your message, and will contact you shortly!</strong></p>
<?php } ?>

 

 

Here's the code of the include file that contains the script to process the form:

 

<?php
if (isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], '.inc.php')) exit;

// remove escape characters from POST array
if (PHP_VERSION < 6 && get_magic_quotes_gpc()) {
  function stripslashes_deep($value) {
    $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
    return $value;
  }
  $_POST = array_map('stripslashes_deep', $_POST);
}

// assume that there is nothing suspect
  $suspect = false;
  // create a pattern to locate suspect phrases
  $pattern = '/Content-Type:|Bcc:|Cc:/i';
  
  // function to check for suspect phrases
  function isSuspect($val, $pattern, &$suspect) {
    // if the variable is an array, loop through each element
    // and pass it recursively back to the same function
    if (is_array($val)) {
      foreach ($val as $item) {
         isSuspect($item, $pattern, $suspect);
      }
    } else {
      // if one of the suspect phrases is found, set Boolean to true
      if (preg_match($pattern, $val)) {
        $suspect = true;
      }
    }
  }

  // check the $_POST array and any subarrays for suspect content
  isSuspect($_POST, $pattern, $suspect);

  if ($suspect) {
    $mailSent = false;
    unset($missing);
  } else {
    // process the $_POST variables
    foreach ($_POST as $key => $value) {
      // assign to temporary variable and strip whitespace if not an array
      $temp = is_array($value) ? $value : trim($value);
      // if empty and required, add to $missing array
      if (empty($temp) && in_array($key, $required)) {
        array_push($missing, $key);
      } elseif (in_array($key, $expected)) {
        // otherwise, assign to a variable of the same name as $key
        ${$key} = $temp;
      }
    }
  }
  
  // validate the email address
  if (!empty($email)) {
    // regex to identify illegal characters in email address
    $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
    // reject the email address if it doesn't match
    if (!preg_match($checkEmail, $email)) {
      $suspect = true;
      $mailSent = false;
      unset($missing);
    }
  }

  
  // go ahead only if not suspect and all required fields OK
  if (!$suspect && empty($missing)) {
  
     // initialize the $message variable
     $message = '';
     // loop through the $expected array
     foreach($expected as $item) {
       // assign the value of the current item to $val
       if (isset(${$item}) && !empty(${$item})) {
         $val = ${$item};
       } else {
         // if it has no value, assign 'Not selected'
         $val = 'Not selected';
       }
       // if an array, expand as comma-separated string
       if (is_array($val)) {
         $val = implode(', ', $val);
       }
       // add label and value to the message body
       $message .= ucfirst($item).": $val\n\n";
     }

    // limit line length to 70 characters
    $message = wordwrap($message, 70);

     // create Reply-To header
     if (!empty($email)) {
       $headers .= "\r\nReply-To: $email";
     }

     
    // send it  

    $mailSent = mail($to, $subject, $message, $headers);
    if ($mailSent) {
      // $missing is no longer needed if the email is sent, so unset it
      unset($missing);
    }
  }
?>

Link to comment
Share on other sites

PFMaBiSmAd,

 

I checked my code, and it looks fine as compared to the example.

 

The example:

When submitting a form, it is possible to use an image instead of the standard submit button with a tag like:

 

<input type="image" src="image.gif" name="foo" />

 

 

My code is

 <input type="image"src="images/contactmedia/contact_btn.png" alt="Submit button" name="send" id="sendusyourcomments" value="Send us your comments!" />

 

But I'll take the image out and use the try the standard form button. Thanks again.

Link to comment
Share on other sites

  • 4 weeks later...

Hi jeweline,

 

I also came across this problem in the same situation. Good news you can keep your image submit by changing your code as follows in the login transaction:-

 

Where you have this line of code:-

 

$loginTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "kt_login1");

 

Change it to:-

 

if(isset($_POST['kt_login1_x'])){
$loginTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "kt_login1_x");
} else {
$loginTransaction->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "kt_login1");
}

 

Hope this helps  ;)

Link to comment
Share on other sites

((if (PHP_VERSION < 6 && get_magic_quotes_gpc()) { )) <<< someone doing there home work nice to see.

 

 

 

yep unfortunately, there loads off incompatibility with img on the button but the standard way is the best way to add a image and not the default button.

 

 

ps. like your coding smart.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.