Jump to content

4 Errors Left with the W3 Validator.


dbznss

Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
}
?>

 

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.