Errors Validating XHTML Page
I've been validating some pages as XHTML 1.0 using the W3C HTML Validation Service.
(http://validator.w3.org/) I've come across 2 familiar snippets of PHP code that make it ack, and have had no luck resolving it! Code:
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Supress Errors At The Page Level? Undefined Index Errors.
I'm creating a simple reply form, and if a form item isn't answered I get an error: "Notice: Undefined index: rb_amntspent in c:inetpubwwwrootmackinawsurvey.php on line 36" even if in the code I allow for an unselected item. (Code at the bottom here.) It works fine otherwise. Now in the past I've made a change to php.ini to repress errors, but for this project I don't have access to the php.ini. Is there a way to supress errors on that page for that session? Or, is there a way to just not get that error at all? Here's a sample of the code that gets the form response. If an item is selected, no error for that question, but if an item is not selected I get the error above even though I still get a successful echo for the "else" or "default" option which occurs if nothing is selected: $rb_visited = $_POST["rb_visited"]; //Have you ever visited Mackinaw City, Michigan? if ($rb_visited == "1") { $rb_visited_reply = "Yes"; } elseif ($rb_visited == "0") { $rb_visited_reply = "No"; } else { $rb_visited_reply = "You did not answer this question"; }; $rb_lastvisit = $_POST["rb_lastvisit"]; //When was your last visit to Mackinaw ity? switch ($rb_lastvisit) { case "1": $rb_lastvisit_reply = "Earlier this year (2003)"; break; case "2": $rb_lastvisit_reply = "Last year (2002)"; break; case "3": $rb_lastvisit_reply = "2 years ago (2001)"; break; case "4": $rb_lastvisit_reply = "3 years ago (2000)"; break; case "5": $rb_lastvisit_reply = "4 or more years ago (1999)"; break; default: $rb_lastvisit_reply = "You did not answer this uestion"; }
Error Validating Page
I am getting an error validating my website for xhtml 1.1 and I think it has something to do with my databases. This is the exact error: non SGML character number ... Does anyone know if there is a quick fix to this. It seems to not recognize characters like ' apostrophes within the html.
Automatically Validating Each Page As It Loads
My whole site is PHP. That means that there are various includes which make up each page so that I can have standard headers/footers/menu, etc If the content of one of these changes, it might break one, some or all pages. I am fairly anal about validation and use W3C to validate my most important pages regularly. However, I am wondering if it is worth the overhead to run the valuator automatically on each page and if there are any errors, to send me a mail. What do you think? Is it worth the performance hit?
Placing Errors On The Page
I have code below (due to length I only included a portion). I am validating an email address. It checks to see if the email field is blank, in the proper format, etc... It prints errors to the screen and everything works perfectly, but the errors always print at the very top of the page and I am having difficulty moving those errors around so they fit nicely into the page design I have. Rather than printing the errors I tried assigning them to variables and printing them elsewhere on the page, but it didn't work and the errors did not try at all. I also tried moving the function to a different part of the page where the errors would print where I wanted them, but I had the same problem as with the variables. I'm kind of in a bind and need this done asap. Does anyone have any thoughts on this? <?php function process_form() { global $db; $firstName = addslashes($_POST['firstName']); $lastName = addslashes($_POST['lastName']); $email = $_POST['email']; $emailHash = md5($email); $active = "n"; // Check syntax $validEmailExpr = "^[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$ %&_-])*" . "@[0-9a-z~!#$%&_-]([.]?[0-9a-z~!#$%&_-])* $"; // Validate the email if (empty($email)) { print "The email field cannot be blank"; return false; } elseif (!eregi($validEmailExpr, $email)) { print "The email must be in the name@domain format."; return false; } elseif (strlen($email) 30) { print "The email address can be no longer than 30 characters."; return false; } elseif (function_exists("getmxrr") && function_exists("gethostbyname")) { // Extract the domain of the email address $maildomain = substr(strstr($email, '@'), 1); if (!(getmxrr($maildomain, $temp) || gethostbyname($maildomain) != $maildomain)) { print "The domain does not exist."; return false; } } $db->query('INSERT INTO users (firstName, lastName, email, hash, active) VALUES (?,?,?,?,?)', array($firstName, $lastName, $email, $emailHash, $active)); $message = " Thank you for signing up for the . Please click on the link below to confirm your registration. If the link is not active, copy-and- paste it into your browser window. http://www.EmailCapture/validateSuccess.php?id=$emailHash "; $subject = ""; $from = ""; mail("$email", "$subject", "$message", "From: $from"); print "<script>window.location=..
Detecting 404 Aqnd Other Page Errors On A Remote Website
Is it possible to detect page errors such as 404 (page not found)? I've searched good but can't find anything, or i'm not looking in the right places. If so, would you be able to detect it even if a htaccess redirects it to an error page?
XHTML 1.1 And PHP
Hey all, I've been trying my hand at the new W3C standard XHTML 1.1, and I've run into a little bit of a problem. For all XHTML documents to be valid, you must use a <?xml version="1.0"?> at the top of every page. As you can see, PHP interprets this as the beginning of PHP code, and I get a parse error? Anyway to fix this without breaking the standard?
Serving Xhtml With Php
Is it possible to serve valid xhtml with php? xhtml requires the 1st line: <?xml version="1.0" encoding="iso-8859-1"?> But php interprets the opening <? as a php statement. If I try to echo this in PHP: <?php echo '<?xml version="1.0" encoding="iso-8859-1"?>' ?> The closing ?of the xhtml bit is interpreted as closing the php. Thus: ' ?> is displayed in the browser. Any way around this?
Php + XHTML Forms
I have made an xhtml form and i want to query a sql database with the entries to the fields using a php script. I can do this using html, what are the differences when using xhtml?
Xhtml Or Html?
I would like to know what HTML standard will be better for PHP webapplications? Right now, I use HTML 4.01 Transitional. And like to know what *you* PHP programmers prefer?
XHTMl Validation And PHP
I don't know where to look for this. I have a form that submits a search query to a db. This all works fine, data is retrieved and displayed properly. I create a session to carry part of the data to the next page, where I update the db based on the results of the search. When I try to validate my page as strict xhtml, all is well, except that PHP adds a hidden input element to my form. In xhtml, input elements must be inside a block-level container (<div>, <p>, <whatever>), but when PHP adds the input element, it doesn't create the container (although it does add the correct end tag), and the validator chokes..
Word To XHTML
I'm looking for a module (COM object/library/anything callable from PHP) to convert Word documents to valid XHTML. Does anyone know of something that does this? It doesn't have to be free.
Coding XHTML
I was wondering what the correct way to integrate xhtml into php? Do you design you your entire site with the xhtml inside of php or only embed the xhtml in php when necessary? For instance would you put your entire xhtml output and php with in a variable and echo it out all at once. Or does it really depend on the situation?
How To Generate An XHTML Form With PHP
Given a list of catalog items contained in a comma delimited text file like this: item_1_name, item_1_shape, item_1_color item_2_name, item_2_shape, item_2_color item_3_name, item_3_shape, item_3_color . . . item_n_name, item_n_shape, item_n_color how can PHP be used to read the text file and then produce a typical XHTML form? The form would look something like this in the browser: Item 1 -- Square -- Red ---- [Quantity Box] Item 2 -- Circle -- White -- [Quantity Box] Item 3 -- Star ---- Blue --- [Quantity Box] . . . The quantity boxes are the typical XHTML form input boxes wherein a website visitor can enter an integer.
XHTML Validation/PHP SSID
I've got one problem with the W3C XHTML (1.1) Validation of one of my pages. Here is the part of code in charge: Code:
Apache2, PHP, And The W3C Xhtml Validator
Sorry if this is the wrong NG to post this in. I have installed Apache2 and PHP on my Mdk 9.2 box. I have made an info.php page to test if php is working. It appears that it is as my info.php is displayed as it should be. The only thing is, when I upload the info.php file to the W3C validator, it complains: **Sorry, I am unable to validate this document because its content type is application/octet-stream, which is not currently supported by this service.** My understanding in this instance, that the page should be processed and delivered to the validator. This isnt happening. Does anyone have an idea why it is failing in this manner? At this stage, I am confused as to whether its a setting in PHP or Apache that needs adjusting. As info.php works through my web-browser, I dont understand why the page isnt being validated.
Nl2br() And XHTML Output Question
I am using nl2br() to output <br> tags. I understand that in PHP4.0.5 and later, this gets output as XHTML-compliant code, <br /> My problem is that I am running an older version of PHP (4.0.1something), but I still want to get valid XHTML from the function. Is there a way to take the <br> tag that nl2br puts out and add the closing slash to make it <br />? I have a feeling I will need to take the <br> and perhaps strip it down, then reformat it somehow to be <br />. My problem is that I don't know how to do this. Any guidance would be greatly appreciated.
Getting The <!DOCTYPE> From An XHTML Document That Was Parsed Using SAX - Possible?
I have been using the SAX library in PHP to parse XHTML documents, and one thing I have noted is that the <!DOCTYPE> line is ignored. I am wondering is there any way to get the <!DOCTYPE> using the SAX functions in PHP? I am looking over the manual, but nothing is jumping out at me... reference: http://us4.php.net/manual/en/ref.xml.php I have thought about loading it using DOM, but I'd rather not consume the memory if possible. And another option would be to just using simple string parsing methods to pull it out of the original document, but again I am hoping that I would be able to do it somehow using the SAX functions... any chance of this?
** SOLUTION: Apache2, PHP, And The W3C Xhtml Validator **
Firstly, thank you to everyone that replied to my OP. I am new to the PHP world and so its great that there are people out there who are prepared to share their knowledge. Anyway, I am developing a website on my home pc. I dont have server-space outside my home. So, I needed to be able to validate my code by file upload to the W3C's html validator at This solution is so easy, I am surprised that my extensive googling didnt provide an answer as it does return MANY hits relating to this search. I thought I would post this so that there is something **out there** for others that come across this problem. My original problem was ...
Valid Xhtml And Control Names
I am really struggling with using form control names such as "gs[]". This will not valid but is tremendously useful in terms of the way that it is handled by php on the server.
$_SESSION['variable_name'], Invalid XHTML And &
The w3 validator identifies the ampersand character as the leading character for special character sequences. And as such, all ampersands should be converted to & when employed as part of a URI. So I configured that manually, for my own parameters. However, I think what I'm seeing here with the validator, is that the validator does not activate cookies and thereby PHP automatically adds an <input> tag with the PHPSESSID. Can anyone tell me how to get PHP to employ the & character in such cases? Also, do any security risks exist? Should I be parsing the address line passed and checking to see if anyone is trying to pass <?PHP tags in that line? The variables working there, are some $_GET['$iPic'] and $_GET['$iCategory'] placed inside the hidden form input tags. I'm seeing that PHP automatically adds an extra <input> tag? Is that correct?
Convincing Firefox That Php Output Is Xhtml
I've got a program that outputs xhtml. When it runs in Firefox, it doesn't render properly, since Firefox assumes it's html. If I capture the output and save it in a file called, say, foo.html, I get the same result. If I rename the file foo.xhtml, the page renders correctly. Firefox uses the extension to decide whether to use the html or xhtml rendering. So... how do I convince Firefox that my php output should be considered xhtml and not html?
Unexpected Behavior When Creating Xhtml Documents
The following has been posted before (2 years ago) but no response was added. Therefor again, the following code for creating xhtml file: <?php error_reporting(6143); $xmlns = "http://www.w3.org/1999/xhtml"; $lang = "en"; $xhtml_1_strict = new DomImplementation(); $dtd_xhtml_1_strict = $xhtml_1_strict->createDocumentType("html", "-// W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/ xhtml1-strict.dtd"); $xhtml_1_strict_document = $xhtml_1_strict->createDocument("", "", $dtd_xhtml_1_strict); $xhtml_1_strict_document->encoding = "UTF-8"; $xhtml_1_strict_document->standalone = "no";
Problem With XHTML Parsers With Embedded HTML (e.g. Firefox Et-al)
I've got some code I wrote in PHP that will generate a new argument string for the browser, but the xhtml parser in Firefox and Opera both complain about my use of &var=value pairs. Below is my code that generates the string : function InvokeURL(url_to_forward_to) { try { var xfamElem = document.getElementById('xFamily'); var mainform = document.getElementById('mainform'); var new_url = url_to_forward_to + "&variable=" + xfamElem.value; mainform.action = new_url; mainform.submit(); } catch(error) { alert("InvokeURL encountered an error :" + error.description); } } This works fine with *many* browsers except the new ones.. With IE on windows (IE6) and Opera, Firefox all complain, Safari and some older browsers seem to work OK.. If I change the line with the new_url variable setting on it to use a & instead, it passes the XHTML tests but no longer works at all.. When using the & it still has that in the URL that shows in the address bar and hence it seems to cause the script on the other end a lot of problems as it is unable to properly parse the URL string. Any ideas on how to portably get around this problem with embedded & created URL's?
[PHP4] Quick Way To Burp Out A PEAR XML Tree To A Valid XHTML Doc?
I am using XMLHttpRequest() from Javascript on the client side. XMLHttpRequest() expects a valid XML/XHTML document as a response. The target for the request is a PHP4 script running on my web server. This script queries an external web server, which returns an XML response to my PHP4 script. My PHP4 script uses the PEAR XML parser to parse the XML response into a PEAR XML tree object, which I modify and add to. All this works fine. Now I need to take the PEAR XML tree object and send it back to the client side Javascript XMLHttpRequest() as a valid XHTML/XML document. What's the fastest and easiest way to get this done?
Validating For !, ?, *, &
Is there any special way that you can use the eregi/ereg expression to find out if an entered value contains any non-numeric value? Currently I am working out if it contains any alpha values. But I don't know how to make sure it doesn't have all the other non-numeric values such as ?, !, #, $, etc etc. Now I know people will say that the best way is to make sure it has numeric values rather than not having alpha but I have one catch... the value can be between 1 and 3 integers. So if I enter 1 numeric, and 1 alpha, I find that it still returns true (using if (eregi("([0-9]{1})", $empid)))
Validating An URL
How do i check if an input in a text box is a valid URL ? For eg, If the input is, http://something.tld/something it is valid. If it is some thing like rsgsegsx, then it is now valid. How do i find it ?
Validating XML Before Parsing In PHP
Does anyone out there is devshed land know of an easy way to valdiate an XML file before trying to parse it in php. I generate XML from a variety of sources and sometimes get funky charecters, bad tag names, and empty tags "<></>" and other wierd stuff. Is there a simple way to check a large xml file (1000k-100,000) before I run my parser on it. Also, when the built in XML parser hits one of these errors in the it just exits with out returning any usefull error. I could post the code if any one would like to see it, but it is very complicated and poorly documented.
Validating Emails
I have this page where if u add an email address it will send an email to u....PHP Code:
Validating Input
What is the most efficient way to validate an input to conform to your needs? I need to make sure an input is a contiguous string with only printable characters (english alphabet+numbers only) and no whitespace or punctuation marks.
Validating Forms
I've read that you can use ereg, preg, eregi as a regular statement for identifying email addresses and all ZEND explanations aside, I still do not get it, not too mention that every bit of code looks different from website to website, and the ones that I've actually tried, had a variety of errors. Do I have to validate using the ACTION tag in the form? I'm asking because I already have a script that takes the information and emails it to recipients, is it best to put something like validate.php as the action, then after the validation is approved, if/else send it to the mail() script? If it's best to send it to a validation script, then to my mail() script Is it possible to send sessions through both steps, because I need to use sessions on my mail script.
Image Validating
I wonder if there is any tutorial on making the "image validating" script on php? Like whenever you want to login to a phpnuke system, it generates a dynamic image, and you'd have to type in the characters before you can log in?
Validating Data
I have data that is in this format: 8-8-19-29-1-4-41 I wanted to write a simple function or regular expression that verified that data is in that format. The numbers should only be 1 or 2 digits. There should be 6 dashes (-) with 7 numbers around the dashes. Here are examples of bad data: 8-19-29-1-4-41 (Only 6 dashes) 5-1-2-3-4-S-67-4 (Includes a letter) 5-1-2-3-4-222-67-4 (has three digits in one space)
Self-validating Form
so after much searching, and thinking, and pondering and planning, i came up with this most amazing thing, and then realized one major flaw which i was hoping you guys might help me overcome. first, we have the magic form. <?php function input($label,$name,$type,$min=0) { return "<div class='".($min?($_POST['submit']&&strlen($_POST[$name])<$min?'error':'required'):'optional')."'>".($_POST['submit'] && strlen($_POST[$name])<$min ? (empty($_POST[$name]) ? '<span>Required.</span>' : '<span>Too short.</span>') : '')."<label for='$name'>$label</label><input type='$type' class='$type' name='$name' id='$name' value='".stripslashes(htmlspecialchars($_POST[$name],ENT_QUOTES))."' /></div> "; } ?> <form method='post' action='<?=$_SERVER['REQUEST_URI']?>'> <fieldset><legend>Registration Information</legend> <?=input('Username','user', 'text', 3)?> <?=input('Password','pass', 'password', 6)?> <?=input('Confirm password','pass2', 'password', 6)?> </fieldset> <fieldset><legend>Profile Information</legend> <?=input('Personal e-mail','email', 'text')?> <?=input('MSN messenger','msnm', 'text')?> </fieldset> <input type='submit' class='submit' name='submit' id='submit' value='Submit'> </form> it creates a pretty little form, with labels and names and id's for styling to your heart's content, and better yet, you can add a "minimum length" parameter, and when you hit submit it'll spit out a little error if you screwed something up. now this is very nice and all, but it occured to me that if a user does actually manage to fill in a simple form.. it won't be until after the form re-rendered that I will be able to determine that there were no errors, since it does the error checking and form-creation at the same time.
Validating With Regex
I need to validate a form for user input file extensions. Then i tried to use the following pattern: To validate html files, pattern => ".html$" To validate css files, pattern => ".css$" To validate js files, pattern => ".js$" The pattern to validate .html extensions worked properly, but for .css and .js simply didn't. What's wrong??? What's is the correct pattern to validate the .css and .js extensions ?
Form Validating
I have a form which will submit to this class for validating. The thing is, how do I go around redirecting back to the form and place "* " on each fields on error with this class? PHP Code:
Validating Input...
What's the best method of validating input characters? I would like to prevent users submitting exotic characters (such as those acquired on Windows Systems by pressing ALT+[keypad number of your choice]) and thought a way of doing this would be to compare the submitted strings with the array keys returned by get_html_translation_table(HTML_ENTITIES), but padding this array out with all the remaining normal keyboard characters. But... am I reinventing the wheel? Surely there must be an existing function along the lines of: valid_charset($str_blah, "iso-8859-01") or somesutch?! Here's hoping...
Validating A URL In A Form
I've been reading a PHP book called "PHP and MySQL for Dynamic Websites (2nd Edit)" and it gives me a way to validate URLs however the method the author give isn't very good as the user is forced to enter the URL in a manner: http://yourdomain.com Obviously someone's personal url can be much different to this, with users adding www. before the domain, different tlds, sub domains, directories, etc.
Form Validating
im making a forum hosting sevice, and i would like to know how do i make it so if the checkbox is unticked they cant register. heres what i have: <?php $tos = $_POST['tos']; if ($tos == "Unchecked" || $tos == ""){//the code carries on is the above how you would check if the checkbox is unticked?
Validating Xml File
I have a series of xml files that contain named character entities (for mdashes, and other special characters). The xml file includes a small DTD containing declarations for these entities, but the structure of the xml is defined by an xml schema file (.xsd). How would I go about validating these documents in php5? If I use the schemaValidate, it appears the partial DTD causes errors. If I remove the DTD, the undeclared entities cause an error.
Validating Dates
I have the following. But I want to change this. - I need the script to check the $c_date field and if it's before June 1, 2007 then shipping will be the 7.95 + quantity, if not then it's going to be 8.95 + quantity. I'm having a hard time with validating the date and creating the if/then. How do I go about this? Code:
Validating A Link
If I have a customer input in a string: $String = "oilers.com"; What I'm doing is storing the links but I want to vaildate it first.. How would I verify the $String is a valid link?
Validating Variable
I have a variable $t - I need to validate it so it allows: - 32-digits, alpha numeric and in the range A-F and 0-9. All letters will be in CAPITALS. and if not display an error message - how do I do this??
Validating Phone Numbers
Hi there, what would you guys suggest be the best way to validate two phone numvers that are required. First being a normal phone number with state calling code, required in the following format (xx)xxxx-xxxxx Only numbers allowed And secondly a mobile number in the format of xxxx-xxx-xxx only numbers allowed? any suggestions would be great whether to do a string check or use reg expressions.
|