dbznss Posted March 7, 2010 Share Posted March 7, 2010 Heres my code: and Here is a link to the form. http://www.bc-multimedia.com/contact.php <?php $YourEmail = Trim(stripslashes($_POST['YourEmail'])); $MyEmail = "dbznss@gmail.com"; $Subject = Trim(stripslashes($_POST['Subject'])); $Name = Trim(stripslashes($_POST['Name'])); $Phone = Trim(stripslashes($_POST['Phone'])); $Message = Trim(stripslashes($_POST['Message'])); $validationOK=true; if (Trim($YourEmail)=="") $validationOK=false; if (Trim($Name)=="") $validationOK=false; if (Trim($Message)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=invalid.html\">"; exit; } $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Phone: "; $Body .= $Phone; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; $success = mail($MyEmail, $Subject, $Body, "From: <$YourEmail>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=sent.html\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=invalid.html\">"; } ?> The form works perfectly but when validating it with W3 I get these errors. Validation Output: 4 Errors 1. Error Line 39, Column 60: document type does not allow element "meta" here <meta http-equiv="refresh" content="0;URL=invalid.html"> ✉ The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed). One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error). 2. Error Line 39, Column 61: end tag for "meta" omitted, but OMITTAG NO was specified <meta http-equiv="refresh" content="0;URL=invalid.html"> ✉ You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">". 3. Info Line 39, Column 5: start tag was here <meta http-equiv="refresh" content="0;URL=invalid.html"> 4. Error Line 39, Column 61: end tag for "html" omitted, but OMITTAG NO was specified <meta http-equiv="refresh" content="0;URL=invalid.html"> ✉ You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">". 5. Info Line 2, Column 1: start tag was here <html xmlns="http://www.w3.org/1999/xhtml"> 6. Error Line 39: Premature end of data in tag html line 2 <meta http-equiv="refresh" content="0;URL=invalid.html"> I just can't seem to solve it. I'm fluent in XHTML and CSS, but only have very basic knowledge in PHP and JavaScript. Quote Link to comment Share on other sites More sharing options...
teamatomic Posted March 7, 2010 Share Posted March 7, 2010 meta tags do not go in the body, they belong in between the <head></head>. As the error told you. *note the text inside the parens. >> One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error). >> HTH Teamatomic Quote Link to comment Share on other sites More sharing options...
dbznss Posted March 7, 2010 Author Share Posted March 7, 2010 I do understand meta tags are only allowed in the head section. however, that still does not solve my problem, I still get errors regardless of where I place the code. I still get OMMITTAG NO errors. No matter what I do I can't seem to close those tags. I solved my problem anyhow by replacing the <meta http-equiv="refresh" content="0;URL=invalid.html"> and <meta http-equiv="refresh" content="0;URL=sent.html"> tags with the lines if (!$validationOK) { Header("Location: invalid.html"); exit; and if ($success){ Header("Location: sent.html"); } else{ Header("Location: invalid.html"); } Thank you for the help though. Quote Link to comment Share on other sites More sharing options...
haku Posted March 7, 2010 Share Posted March 7, 2010 1) Why are you showing us PHP in the HTML section? PHP is irrelevant. 2) <meta http-equiv="refresh" content="0;URL=invalid.html" /> Quote Link to comment Share on other sites More sharing options...
dbznss Posted March 7, 2010 Author Share Posted March 7, 2010 The moderator moved my topic out of the PHP section, and into the HTML section. Obviously he didn't read it. A topic you are watching has been moved to another board by thorpe. View the topic at: http://www.phpfreaks.com/forums/index.php?topic=290287.new;topicseen#new Unsubscribe to this topic by using this link: http://www.phpfreaks.com/forums/index.php?action=notify;topic=290287.0 Regards, The PHP Freaks Forums Team. Quote Link to comment Share on other sites More sharing options...
haku Posted March 8, 2010 Share Posted March 8, 2010 Fair enough - you didn't post PHP in the HTML section, you posted it in the PHP section. My apologies. The moderator was right to move it though, you posted in the wrong section as it was an HTML question. Quote Link to comment Share on other sites More sharing options...
dbznss Posted March 8, 2010 Author Share Posted March 8, 2010 Actually it wasn't. What I was really asking for was a better line of code for the <meta> PHP line. I should have phrased it better I guess, but I solved the issue on my own anyhow. Quote Link to comment Share on other sites More sharing options...
haku Posted March 8, 2010 Share Posted March 8, 2010 And I gave you a better line of HTML code that will solve your problem and doesn't require any php. Quote Link to comment Share on other sites More sharing options...
dbznss Posted March 8, 2010 Author Share Posted March 8, 2010 That line of code won't work. The meta tags were used with an if...else... statement. The PHP was part of an email contact form. If the user didn't fill in the form properly it would send them to invalid.html. If they filled in everything correctly it would send them to sent.html. Simply adding a meta tag in the head wouldn't do the trick, because it's not linked to the if...else... statement. Hence, why this post is PHP and not HTML. Take a look at the finished form. Heres my code: and Here is a link to the form. http://www.bc-multimedia.com/contact.php Thank you anyways for trying however. Quote Link to comment Share on other sites More sharing options...
haku Posted March 9, 2010 Share Posted March 9, 2010 But you said yourself: I still get OMMITTAG NO errors. No matter what I do I can't seem to close those tags. That's because the meta tag is a self-closing tag. The code I gave you self closes it. That will get rid of your OMITTTAG NO errors, which is what you yourself said the problem is. Assuming you have your <meta> tags in the head. Quote Link to comment Share on other sites More sharing options...
dbznss Posted March 9, 2010 Author Share Posted March 9, 2010 It's giving me the OMMITAG NO errors because in order for it to work as PHP it has to look like this: <meta http-equiv=\"refresh\" content=\"0;URL=invalid.html\">"; Regardless of whether I do: <meta http-equiv=\"refresh\" content=\"0;URL=invalid.html\" />"; or not it doesn't solve the issue. W3 validator tells me to put it like you mentioned, but then it no longer works as part of the PHP if...else...statement. So the only solution I can see is to replace the meta tag all together with a location line. This is why my post belongs in the PHP section and not HTML. Quote Link to comment Share on other sites More sharing options...
haku Posted March 9, 2010 Share Posted March 9, 2010 Alright then, I can see why it's a php problem. You weren't confused on why the error was happening, you were confused on how to make PHP output the text the way you wanted. You must have some other problem however, as this code will work whether in an if/else statement or not: echo "<meta http-equiv=\"refresh\" content=\"0;URL=invalid.html\" />"; See this example. It validates fine. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php if(1 == 1) { echo "<meta http-equiv=\"refresh\" content=\"0;URL=invalid.html\" />"; } else { echo "<meta http-equiv=\"refresh\" content=\"0;URL=invalid.html\" />"; } ?> <title>Untitled Document</title> </head> <body> <p>text</p> </body> </html> There are two other ways you can do this however 1) Use single quotes for your echo statement: echo '<meta http-equiv="refresh" content="0;URL=invalid.html">'; This method will even run a little quicker as it doesn't have to parse the echo statement for variables. Strings in double quotes are parsed for variables, which takes a minute amount more time to process (though in all reality the amount of time is so small as to not even matter). 2) Exit out of PHP to print your statement: <?php if($something == 'something') { ?> <meta http-equiv="refresh" content="0;URL=invalid.html"> <?php } else { ?> <p>Something else</p> <?php } ?> Quote Link to comment Share on other sites More sharing options...
haku Posted March 9, 2010 Share Posted March 9, 2010 I should also add that you should be careful with the meta refresh tag, as search engines frown upon it. You would be better off using a php header to redirect the user if there is a problem. Quote Link to comment Share on other sites More sharing options...
dbznss Posted March 9, 2010 Author Share Posted March 9, 2010 Now that's more what I'm looking for, thank you very much. as of right now I actually am using a header tag: if ($success){ Header("Location: sent.html"); } else{ Header("Location: invalid.html"); } Quote Link to comment Share on other sites More sharing options...
haku Posted March 9, 2010 Share Posted March 9, 2010 That is definitely the best way to do it. Quote Link to comment Share on other sites More sharing options...
dbznss Posted March 9, 2010 Author Share Posted March 9, 2010 thank you very much for all your help haku. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.