简体   繁体   中英

This doesn't works in IE bt in all other browsers

This is the code of my form

<form method="post" style="margin-left:15px;margin-top:6px;" onsubmit="return map_Email_Validation();">

    <table>
        <tr>
         <td colspan="2" class="faceboxheading" style="white-space:nowrap;">Share your map information with your friends</td>
            <td colspan="2" align="left"><a href="javascript:void(0);" class="hrf_btn" onclick="hide_facebox();">[x]</a></td>
        </tr>
      <tr></tr>
      <?php if($error) {?>
      <tr>
        <td colspan="2" class="faceboxheading"><?php echo $error;?></td>
      </tr>
      <?php }?>
      <tr>
        <td width="100px">To Email</td>

        <td width="250px"><input type="text" name="ToID" id="ToID" style="width:274px;" onkeyup="dis();"/></td>
      </tr>
      <tr>
        <td>From Email</td>
        <td><input type="text" name="fromID" id="fromID" style="width:274px;" onkeyup="dis();" value="'.$g['email'].'" /></td>
      </tr>
      <tr>
        <td>Subject</td>
        <td><input type="text" name="subject" id="subject" style="width:274px;" onkeyup="dis();"/></td>
      </tr>
      <tr>
        <td>URL</td>
        <td><input type="text" readonly="readonly" name="URL" id="URL" size="42" style="width:274px;"/></td>
      </tr>
      <tr>
        <td>Message</td>
        <td valign="top"><textarea id="message" name="message" cols="25" rows="4" style="width:274px;" onkeyup="dis();"></textarea></td>
      </tr>
     <tr><td></td>  
   <td> <input type="image" style="margin-left:-2px;" src="http://jersey.cimaps.co.uk/jersey_dev/templates/default/images/send.png" name="submitbtn" id="submitbtn" value="Send"/></td>

</td></tr>

    </table>
  </form>

The functions are

function map_Email_Validation()
{

        var ToID = document.getElementById('ToID').value;      
        //var fromID = document.getElementById('fromID').value;
        var subject = document.getElementById('subject').value;
        var message = document.getElementById('message').value;
        var char_at=ToID.indexOf("@");
        var char_dot=ToID.indexOf(".");
        var char_dolar=ToID.indexOf("$");
        var char_hash=ToID.indexOf("#");
        var at="@";

                var lat=ToID.indexOf(at);
if(ToID.length<1)
        {
            alert('Please enter To Email!');
            return false;
        }
        else if((char_at==-1)||(char_dot==-1)||(char_dolar!=-1)||(char_hash!=-1))
        {
            alert( 'Invalid To Email!');
            return false;
        }
        else if((char_at==0)||(char_dot==1)||(char_dot==char_at+1))
        {
            alert( 'Invalid To Email!');
            return false;
        }
if(subject.length<1)
        {
            alert( 'Please enter Subject!');
            return false;
        }
        if(message.length<1)
        {
            alert( 'Please enter Message!');
            return false;
        }
        else if(message.length>100)
        {
            alert( 'Message can have only 100 characters!');
            return false;
        }

return true;    
}
code in index page is
if(isset($_POST['submitbtn']))
{
    //echo "set";

    $flag=true;
    $error="";
    /*Getting Values**********************/
    $ToID=$_POST['ToID'];
    $fromID=$_POST['fromID'];
    $subject=$_POST['subject'];
    $URL=$_POST['URL'];
    $message=$_POST['message'];

    /*Validating the data*****************/
    if(strlen($ToID)==0)
    {
        $flag=false;
        $error.="Enter To email address field"; 
    }
    elseif(!preg_match_all("|^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$|U",$ToID,$arr))
    {
        $flag=false;
        $error.="Invalid To email address"; 
    }
if(strlen($subject)==0)
    {
        $flag=false;
        $error.="Enter subject field";  
    }
    if(strlen($message)==0)
    {
        $flag=false;
        $error.="Enter message field";  
    }
    elseif(strlen($message)>100)
    {
        $flag=false;
        $error.="Message can have only 100 charaters";  
    }

    if($flag=="true")
    {

        $urltoemail = "<html><head><title>Forgot Password</title></head><body>
<table><tr><td>".$message."</td></tr><tr><td><a href='{$URL}'>Click here for viewing map</a></td></tr></table></body></html>";
        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
        if(strlen($fromID)==0)
        $fromID = 'info@cimaps.co.uk';
        $headers .= "From: $fromID \r\n";
        mail($ToID,$subject,$urltoemail,$headers);
        //header("Location:".$_SERVER['SCRIPT_NAME']);
    }

}

The mail doesnot sent in IE but successfully in all other browsers..Any idea?

It's really hard to read your code and determine what you are asking.

However, since mail is not a client-side activity, this is almost certainly an issue with whatever is being sent to the server (ie in the POST). Try putting a breakpoint in your code when the page's POST is first received and compare the POST values from IE to Chrome/Firefox. I'm guessing you'll see that they are different and can quickly fix it.

Update - what if you try doing this instead of looking for the named submit:

 if (!empty($_POST))

I'm not sure and I don't fully understand the fix that you had made. But for me, the check if(isset($_POST['submitbtn'])) fails in both IE8 and FF4; it worked fine in Chrome12. And the reason is that when you are using an <input type="image"> kind of button to submit the form, you need to check it like this:

if(isset($_POST['submitbtn_x'])) {
    ...
    ...
}

And that check will work on all browsers. To check this, you may like to do a print_r($_POST) just before where the if() starts and see how it looks like.

Hope this helps to solve your problem.

/Abhay

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM