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

    Form issue with IE7 and below

    Hey,

    I have a compatibility issue with my contact form with Internet Explorer 7 and below. When I fill out the form correctly and click submit, nothing happens. I have posted the html, js and php, though I took the js out and that didn't help, so at a guess I'd say it's an issue with the php. All newer browsers function perfectly using this code.

    Here is my html of the form

    Code:
    <form name="contactform" action="contactengine.php" method="post" class="formcontainer" onSubmit="javascript:validate(); return false;">
                 	<label>Name:</label>
             	   	<input type="text" name="name"/>
                    <label>Email:</label>
             	   	<input type="text" name="email"/>
                    <label>Subject:</label>
             	   	<input type="text" name="subject" id="subject"/>
                    <label>Message:</label>
             	   	<textarea name="message"></textarea>
    
                	<button> Submit! </button> 
             </form>
    The javascript:

    Code:
    function validate()
    	{
    		if (document.contactform.name.value =="")
    	    {
    			alert("Name can't be left blank!");
    			return false;
    		}
    				if (document.contactform.email.value =="" || (document.contactform.email.value.search("@") == -1 ||( document.contactform.email.value.search("com") == -1 && document.contactform.email.value.search("net") == -1 && document.contactform.email.value.search("au") == -1 && document.contactform.email.value.search("org") == -1)))
    	    {
    			alert("Please enter a valid email address!");
    			return false;
    		}
    		
    		if (document.contactform.subject.value =="")
    	    {
    			alert("Subject can't be left blank!");
    			return false;
    		}
    		
    		if (document.contactform.message.value =="")
    	    {
    			alert("Please enter a comment or question!");
    			return false;
    		}	
    		document.contactform.submit();
    	}
    And finally, the PHP:

    Code:
    <?php
    
    $EmailFrom = "contact@website.com";
    $EmailTo = "myemail@example.com";
    $Subject = $_REQUEST['subject'];
    $Name = Trim(stripslashes($_POST['name'])); 
    $Email = Trim(stripslashes($_POST['email'])); 
    $Message = Trim(stripslashes($_POST['message'])); 
    
    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }
    
    if(isset($_POST["title"]) && strlen($_POST["title"])){
        die("SPAM BOT");
    }
    
    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";
    
    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
    }
    ?>
    Thanks in advance for any comments/help.

    Toby.
    Last edited by vinyl-junkie; 07-09-2014 at 09:14 AM. Reason: altered email address at request of OP

  • #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
    You forgot to tell us what problem you're having.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    As Fumigator says, what part of this isn't working? - The javascript, the php, what?
    I can't really think of anything to write here now...

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Haha wow woops. The form doesn't work in IE 7 and below. I fill out the fields and click submit, and simply nothing happens.

    I'm an alright coder, but I'm not good with compatibility issues with IE versions.

  • #5
    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
    Code:
    onSubmit="javascript:validate(); return false;"
    Returning false is going to cause the form to not submit. I thought this was true for all browsers but I'm wrong apparently... I'll test it real quick.

  • #6
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    Code:
    onSubmit="javascript:validate(); return false;"
    Returning false is going to cause the form to not submit. I thought this was true for all browsers but I'm wrong apparently... I'll test it real quick.
    It only returns false if it doesn't validate through the js. I just re tested it just now without the validation in the form and it still doesn't work with IE 7 and below.

    It works with "onClick="this.form.submit()"" in the button attributes, but then that overrides the validation and sends it anyway.
    Last edited by Tobe_Sta; 05-22-2011 at 04:14 AM.

  • #7
    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
    Try using <input type="submit" value="submit" name="sub"> instead of <button>Submit!</button>. Make sure you don't name the <input> element "submit"-- that can mess things up.

  • #8
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Fumigator - Thank you so much! That worked perfectly.

    One last thing though. In IE 8 and below, the js code "alert("Please enter a valid email address!");" doesn't work. The form is prevented from being sent, but there is nothing telling the end user why it hasn't been sent.

    Is there a more conventional way of "alerting" the user to the fields that need to be filled in.

  • #9
    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
    To clarify, the alert() command works fine on all IE browsers. If it's not working in your script, there's something else going on. But generally, you can manipulate the DOM to inject html into the page (document.write() or elementID.innerHTML() for example), or you can reload the page and include error messages within the DOM when the page is built (generated from your PHP script).

    You really shouldn't be relying solely on client-side validation anyway; it's easy to turn off Javascript and then anything can get to your PHP script. If you aren't validating the data coming into your PHP script, your process may fail because the data is unreliable.

  • #10
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks fine in all browsers except IE7 and I assume below. IE7 seems to be inserting a carriage return before the 'Contact' heading making the alignment off compared to the other pages. I guess it has something to do with the <form> tag. As this page is generated dynamically, I can't simply move the <form> tag further down the page.


  • #11
    Regular Coder
    Join Date
    Sep 2011
    Posts
    128
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Validate the form with javascript is a good way, but like someone told before. Javascript can be shut off very easily.

    That's why you also need to validate this in the PHP page.


  •  

    Posting Permissions

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